jboss7.1 在modules中引入其他jar包

今天在用jboss7.1部署项目的时候,报了一个问题,如下:

Exception in thread "Thread-138" java.lang.NoClassDefFoundError
16:07:51,508 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.class$(DefaultTypeMappingRegistry.java:64)
16:07:51,509 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.createDefaultMappings(DefaultTypeMappingRegistry.java:406)
16:07:51,510 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.createDefaultMappings(DefaultTypeMappingRegistry.java:311)
16:07:51,511 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.(DefaultTypeMappingRegistry.java:131)
16:07:51,512 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.(DefaultTypeMappingRegistry.java:137)
16:07:51,513 ERROR [stderr] (Thread-138) at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.(DefaultTypeMappingRegistry.java:118)
16:07:51,514 ERROR [stderr] (Thread-138) at org.codehaus.xfire.jaxb2.JaxbTypeRegistry.(JaxbTypeRegistry.java:15)
                                                      .............................
16:07:51,520 ERROR [stderr] (Thread-138) at java.lang.Thread.run(Thread.java:662)
16:07:51,521 ERROR [stderr] (Thread-138) Caused by: java.lang.ClassNotFoundException: org.jdom.Element from [Module "deployment.xxxx.war:main" from Service Module Loader]
16:07:51,522 ERROR [stderr] (Thread-138) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
16:07:51,523 ERROR [stderr] (Thread-138) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
16:07:51,523 ERROR [stderr] (Thread-138) at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
16:07:51,524 ERROR [stderr] (Thread-138) at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
16:07:51,525 ERROR [stderr] (Thread-138) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
16:07:51,526 ERROR [stderr] (Thread-138) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
16:07:51,527 ERROR [stderr] (Thread-138) at java.lang.Class.forName0(Native Method)
16:07:51,527 ERROR [stderr] (Thread-138) at java.lang.Class.forName(Class.java:171)
16:07:51,528 ERROR [stderr] (Thread-138) ... 14 more


一看就是缺少了个jar包,后来到jboss下去找,发现有对应的jar包。路径如下:/jboss-as-7.1.1.Final/modules/org/jdom/main/jdom-1.1.2.jar

那为什么还是找不到呢?

原因是jboss7.1是采用多个类加载器,跟weblogic是有区别的。所以有两种解决方案:

方案1、将jdom-1.1.2.jar放到项目的lib下,重新发布就OK了,这样只有这一个项目可以用此包。如果在jboss下部署其他项目,还是会报这个问题。

方案2、将jdom-1.1.2.jar设置成jboss下全局包。在配置文件standalone.xml的下增加如下代码:


               
         
    

其中main是固定的。org.jdom是从/jboss-as-7.1.1.Final/modules/org/jdom/main/module.xml中获取的name值,如下:

你可能感兴趣的:(java)