Chris
Chris

Reputation: 5654

JBoss 7.1.1: add rt.jar of jre to classpath

My goal is to deploy an ear file in JBoss 7.1.1. One of the classes in the ear file (which I cannot change) is using sun.net.util.IPAddressUtil class of JRE's rt.jar.

In my IDE (eclipse) resolves this class and it compiles normally. But when I try to deploy (the ear containing the class) on JBoss 7.1.1, it gives me java.lang.NoClassDefFoundError: sun/net/util/IPAddressUtil. JAVA_HOME variable is set in my machine and I see that both JBoss and eclipse use the same JDK (1.6.X)

When I bundle the EAR with rt.jar in lib folder, the EAR deploys properly (which is a bad approach).

I have looked at JBoss community which says to configure as module for any third-party jars. However, the class I need is with in the rt.jar, I'm not in favor of adding it as module

Is there a way to configure JBoss 7.1.1 to manually look at %JAVA_HOME%/jre/lib/rt.jar ?

Thanks in advance.

Upvotes: 5

Views: 10611

Answers (2)

Sundayu
Sundayu

Reputation: 1

See wildfly developer guide#1.8. Accessing JDK classes

Not all JDK classes are exposed to a deployment by default. If your deployment uses JDK classes that are not exposed you can get access to them using jboss-deployment-structure.xml with system dependencies:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
    <dependencies>
        <system export="true">
            <paths>
                <path name="sun/net"/>
            </paths>
        </system>
    </dependencies>
</deployment>

Upvotes: 0

GeertPt
GeertPt

Reputation: 17854

JBoss 7 use jboss-modules technology for modular class-loading, similar to OSGi. It will use rt.jar and a bunch of libraries in its own lib directory to start the application server itself. But when it will load your web application, it will create a custom classloader which restricts what classes it will see, based on the module dependencies it declares.

To declare module dependencies, you need to include a jboss-deployment-structure.xml in the META-INF directory of your EAR (or WEB-INF for a WAR). See https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7. To declare a dependency on classes in the rt.jar, you need a <system> dependency:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system export="true">
                <paths>
                    <path name="sun/net/util"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

You could also try to extract the IPAddressUtil class and package it as a separate module. You can get the sources from the openjdk, e.g. http://www.docjar.com/html/api/sun/net/util/IPAddressUtil.java.html

Upvotes: 15

Related Questions