I want load .class file from a given directory so, i put compiled file inside the directory /opt/wildfly-8.2.1.Final/modules/packagename/ and also server load the classes from the same directory rather than war(WEB-INF/classes/packagename/).
Asked
Active
Viewed 1,137 times
0
-
So you want the class to be loaded from `/opt/wildfly-8.2.1.Final/modules/packagename/` rather than `WEB-INF/classes/packagename/`? – Konrad Botor Jul 13 '18 at 08:54
-
@Konrad Botor, Yes – MANOJ Jul 13 '18 at 08:56
1 Answers
1
I haven't tried this method myself, but you must:
- Move
/opt/wildfly-8.2.1.Final/modules/packagename/
to/opt/wildfly-8.2.1.Final/modules/custom-classes/main/packagename/
- Add file
module.xml
to/opt/wildfly-8.2.1.Final/modules/custom-classes/main/
- Add file
jboss-deployment-structure.xml
to your war. - Undeploy the war, restart the server and then redeploy the war.
Content of module.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="custom-classes">
<resources>
<resource-root path="."/>
</resources>
</module>
Contents of jboss-deployment-structure.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="custom-classes" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Edit: If you want to add jars as well as non-jared classes to your module you must not only copy jars to /opt/wildfly-8.2.1.Final/modules/custom-classes/main/
, but also list jars in module.xml
like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="custom-classes">
<resources>
<resource-root path="."/>
<resource-root path="dependency1.jar"/>
<resource-root path="dependency2.jar"/>
<!-- and so on for other jars -->
</resources>
</module>
Resources:

Konrad Botor
- 4,765
- 1
- 16
- 26
-
Thanks for reply but i am getting an error Failed to define class com.demo.project.controller.LoginController in Module "custom-classes:main" from local module loader (finder: local module finder (roots: /opt/wildfly-8.2.1.Final/modules,/opt/wildfly-8.2.1.Final/modules/system/layers/base)): java.lang.LinkageError: Failed to link com/demo/project/controller/LoginController (Module "custom-classes:main" from local module loader (finder: local module finder (roots: /opt/wildfly-8.2.1.Final/modules,/opt/wildfly-8.2.1.Final/modules/system/layers/base))) – MANOJ Jul 13 '18 at 11:57
-
As described in `Class Loading in WildFly` classes from modules are loaded before classes from war, so if the class(es) placed inside the module depend on class(es) inside the war the module won't load – Konrad Botor Jul 13 '18 at 12:09
-
i have put all dependencies (jar) inside modules(/opt/wildfly-8.2.1.Final/modules/custom-classes/main/)but i got the same error, can you please suggest? – MANOJ Jul 18 '18 at 11:16