5

我的目标是在 JBoss 7.1.1 中部署一个 ear 文件。ear 文件中的一个类(我无法更改)是使用sun.net.util.IPAddressUtilJRE 的rt.jar类。

在我的 IDE (eclipse) 中解析了这个类并且它可以正常编译。但是当我尝试在 JBoss 7.1.1 上部署(包含类的耳朵)时,它给了我java.lang.NoClassDefFoundError: sun/net/util/IPAddressUtil. JAVA_HOME在我的机器中设置了变量,我看到 JBoss 和 eclipse 都使用相同的 JDK (1.6.X)

当我将 EAR 与 lib 文件夹中的rt.jar捆绑在一起时,EAR 会正确部署(这是一种不好的方法)。

我看过JBoss 社区,它说要为任何第三方 jar 配置为模块。但是,我需要的类在rt.jar中,我不赞成将其添加为模块

有没有办法将 JBoss 7.1.1 配置为手动查看%JAVA_HOME%/jre/lib/rt.jar

提前致谢。

4

1 回答 1

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

于 2012-09-21T07:58:42.537 回答