Search code examples
jbosswildflyclassloaderwildfly-8war-filedeployment

How to force wildfly-8.2.1.Final to load .class from a directory rather than war?


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/).


Solution

  • I haven't tried this method myself, but you must:

    1. Move /opt/wildfly-8.2.1.Final/modules/packagename/ to /opt/wildfly-8.2.1.Final/modules/custom-classes/main/packagename/
    2. Add file module.xml to /opt/wildfly-8.2.1.Final/modules/custom-classes/main/
    3. Add file jboss-deployment-structure.xml to your war.
    4. 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: