2014-12-11 73 views
0

在爲Log4j2添加新模塊後,Wildfly日誌在啓動時爆炸並出現多個ClassNotFoundException異常。它看起來好像是在模塊中尋找其他Java EE類的模塊,而新定義的模塊沒有任何關係。當使用新的模塊依賴關係時,Wildfly ClassNotFoundException

這裏是一個例外:

17:52:57,865 WARN [org.jboss.modules] (ServerService Thread Pool -- 52) Failed to define class org.apache.logging.log4j.core.net.AbstractJMSReceiver in Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base)): java.lang.LinkageError: Failed to link org/apache/logging/log4j/core/net/AbstractJMSReceiver (Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base))) 
     at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:428) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final] 
     at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_67] 
     at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_67] 
     at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final] 
     at org.apache.logging.log4j.core.config.plugins.ResolverUtil.addIfMatching(ResolverUtil.java:436) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.plugins.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:411) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.plugins.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:367) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.plugins.ResolverUtil.findInPackage(ResolverUtil.java:264) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:174) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:130) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.config.BaseConfiguration.start(BaseConfiguration.java:152) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:341) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:386) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:149) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:84) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:35) [log4j-core-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:444) [log4j-api-2.0-rc1.jar:2.0-rc1] 
     at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:389) [log4j-api-2.0-rc1.jar:2.0-rc1] 
     at com.extraliga.domain.ExtraligaEntity.<init>(Unknown Source) [extraliga-persistence.jar:] 
     at com.extraliga.domain.util.EmailConverter.<init>(Unknown Source) [extraliga-persistence.jar:] 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_67] 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_67] 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_67] 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_67] 
     at java.lang.Class.newInstance(Class.java:374) [rt.jar:1.7.0_67] 
     at org.hibernate.cfg.annotations.reflection.XMLContext.setLocalAttributeConverterDefinitions(XMLContext.java:206) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.annotations.reflection.XMLContext.addDocument(XMLContext.java:113) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.Configuration.add(Configuration.java:528) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.Configuration.add(Configuration.java:517) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.Configuration.add(Configuration.java:512) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.Configuration.add(Configuration.java:686) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:724) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1163) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:846) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.1.Final.jar:4.3.1.Final] 
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final] 
     at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:] 
     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final] 
     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final] 
     at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_67] 
     at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474) [wildfly-security-manager-1.0.0.Final.jar:1.0.0.Final] 
     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final] 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67] 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67] 
     at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67] 
     at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final] 
Caused by: java.lang.NoClassDefFoundError: javax/jms/MessageListener 
     at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_67] 
     at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_67] 
     at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final] 
     ... 63 more 
Caused by: java.lang.ClassNotFoundException: javax.jms.MessageListener from [Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base))] 
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final] 
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final] 
     ... 67 more 

目前,我只是想給我的部署持久性單元的存檔,以確保我正確映射一切,這個檔案取決於Log4j2。在我的堅持存檔的META-INF目錄下我有一個JBoss部署,structure.xml,看起來像這樣:

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure> 
    <deployment> 
     <exclusions> 
      <module name="org.apache.log4j"/> 
     </exclusions> 
     <dependencies> 
      <module name="org.apache.log4j2"> 
       <imports> 
        <include path="META-INF"/> 
       </imports> 
      </module> 
     </dependencies> 
    </deployment> 
</jboss-deployment-structure> 

我的模塊是由下面的目錄結構Wildfly定義:

$WILDFLY_HOME/modules/org/apache/log4j2/main/ 
    log4j-api-2.0-rc1.jar 
    log4j-core-2.0-rc1.jar 
    module.xml 

最後我module.xml如下:

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.1" name="org.apache.log4j2"> 
    <resources> 
     <resource-root path="log4j-api-2.0-rc1.jar"/> 
     <resource-root path="log4j-core-2.0-rc1.jar"/> 
    </resources> 
    <dependencies> 
     <module name="com.lmax.disruptor"/> 
     <module name="javax.api"/> 
     <module name="javax.servlet.api"/> 
    </dependencies> 
</module> 

這似乎很奇怪,wildfly甚至會試圖尋找一個javax.jms.MessageListener在這一點上,更使其正在尋找它「來自org.apache.log4j2:主」

有沒有人有任何想法如何解決這個異常?

回答

1

WildFly並非試圖尋找javax.jms.MessageListenerorg.apache.logging.log4j.core.net.AbstractJMSReceiver是。我不知道log4j2有多少其他依賴項,但至少需要添加javax.jmx作爲依賴項。

+0

依賴關係樹(http://logging.apache.org/log4j/2.x/log4j-core/dependencies.html#Dependency_Tree)提到了org.jboss.spec.javax.jms:jboss-jms-api_1。 1_spec:jar:1.0.1.Final – 2014-12-11 09:08:14

+0

這樣做,事實證明該模塊需要幾個庫,包括來自第三方的兩個新模塊。有可能是一個更簡單的方法來做到這一點,但它現在工作。謝謝。 – 2014-12-11 16:12:19

+0

也是這樣,javax.servlet.api依賴完全不需要。 – ctomc 2014-12-11 21:54:55