Search code examples
javawildflyjboss7.xnoclassdeffounderrorjboss-modules

How to access JDK tools.jar javac from application deployed in JBoss 7 or WildFly


I am deploying an application that tries to use javac and finally fails with java.lang.NoClassDefFoundError: com/sun/tools/javac/Main

How should I make javac from tools.jar available to the application deployed in JBoss 7 or WildFly ?


Solution

  • Here is the process I followed to create a JBoss module for javac:

    mkdir -p modules/com/sun/tools/javac/main
    ln -s /usr/java/latest/lib/tools.jar modules/com/sun/tools/javac/main/tools.jar
    

    Create modules/com/sun/tools/javac/main/module.xml with content:

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.1" name="com.sun.tools.javac">
        <resources>
            <resource-root path="tools.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <system export="true">
                <paths>
                    <path name="com/sun/tools/javac"/>
                </paths>
            </system>
        </dependencies>
    </module>
    

    Note: I used a symbolic link because absolute path seems not supported by resource-root path attribute.

    Then either add Dependencies: com.sun.tools.javac in META-INF/MANIFEST.MF or create a jboss-deployment-structure.xml file to declare use of this new module by the application: https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.2/html/Development_Guide/Add_an_Explicit_Module_Dependency_to_a_Deployment1.html