JBoss 7.1.1: add rt.jar of jre to classpath
Asked Answered
R

2

5

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.

Redolent answered 19/9, 2012 at 10:16 Comment(1)
The reason you don't see this class is because it's not part of the API. The solution is to fix your code to not use sun.net.util.IPAddressUtil. There is no guarantee that it won't be removed at some point.Pagandom
O
15

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

Olav answered 21/9, 2012 at 7:58 Comment(2)
Just bit of comment, Jboss7 is not OSGI based but it does support osgi, it is jboss-modules based.Frowst
it's better to change the pointer, than to change the bundles.Venn
C
0

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>
Civilize answered 10/11, 2023 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.