I have a JBoss server that has an ear file. My ear file has a war file. The war file has a jar file "server-artifact.jar". My server's service endpoint is in that jar. The class in the jar file loads a class dynamically to perform an action.
Class<?> clazz = (Class<?>) Class.forName("com.test.TestExternalAccess");
try {
TestExternalAccessParent extClassObject = (TestExternalAccessParent) clazz.newInstance();
extClassObject.sayHelloToExternalAccess();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
The jar file that contains "TestExternalAccessParent" which is an interface, is part of the war file too. The class "TestExternalAccess" is a concrete class that is meant to be a pluggable unit for my server. In order to achieve this, i created a jboss module and put it in the modules folder (how?):
<module xmlns="urn:jboss:module:1.1" name="com.test">
<resources>
<resource-root path="externalLibrary-0.0.1-SNAPSHOT.jar"/>
</resources>
</module>
I also edited the jboss-deployment-structure.xml and added the dependency
<module name="com.test" />
I start my server and run it. I get the following exception when the dynamic loading of the class happens :
java.lang.ClassNotFoundException: com.test.TestExternalAccess from [Module "deployment.myservice-ear.ear:main" from Service Module Loader]
Some things i have tried: 1) Tried loading a class from the external module that does not implement an interface in the jar file of the main ear file and that works fine. 2) Changed my module to include the jar file that contains the interface.
<module xmlns="urn:jboss:module:1.1" name="com.test">
<resources>
<resource-root path="externalLibrary-0.0.1-SNAPSHOT.jar"/>
<resource-root path="externalParentLibrary-0.0.1-SNAPSHOT.jar"/>
</resources>
</module>
That works fine too. 3) Added the following dependency to my module:
<dependencies>
<module name="deployment.myservice-ear.ear"/>
</dependencies>
That DOES NOT work.
The classloader that loaded my ear uses another classloader to load my external module and gain access to the classes in that module. But the classes in my external module cannot seem to be able to access the jars in the ear. How can i make this happen? I want to add external library modules that has access to classes in my server's ear file classes.