我有一個應用程序正常工作,直到我引入了下列Maven依賴項。添加Maven依賴項導致java.lang.ClassNotFoundException
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler-jdk</artifactId>
<version>3.0.0</version>
</dependency>
介紹了以下相關後,廣口瓶得到正確建立,沒有編譯器異常,但運行應用程序時,它有以下例外失敗:
異常1:
Exception in thread "2/streamJsonParser:StreamingJsonParser" java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
at org.apache.log4j.spi.LoggingEvent.<init>(LoggingEvent.java:165)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at org.slf4j.impl.Log4jLoggerAdapter.error(Log4jLoggerAdapter.java:540)
at com.datatorrent.stram.engine.StreamingContainer$2.run(StreamingContainer.java:1431)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.spi.ThrowableInformation
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
例外2:
Exception in thread "[email protected]" java.lang.NoClassDefFoundError: com/google/common/collect/LinkedListMultimap$3
at com.google.common.collect.LinkedListMultimap.values(LinkedListMultimap.java:846)
at org.apache.hadoop.hdfs.PeerCache.clear(PeerCache.java:271)
at org.apache.hadoop.hdfs.PeerCache$1.run(PeerCache.java:128)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.LinkedListMultimap$3
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
例外3:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/helpers/NullEnumeration
at org.apache.log4j.Category.getAllAppenders(Category.java:413)
at org.apache.log4j.Category.closeNestedAppenders(Category.java:226)
at org.apache.log4j.Hierarchy.shutdown(Hierarchy.java:467)
at org.apache.log4j.LogManager.shutdown(LogManager.java:267)
at com.datatorrent.stram.engine.StreamingContainer.main(StreamingContainer.java:332)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.helpers.NullEnumeration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 morexception in thread "Thread-3" java.lang.NoClassDefFoundError: org/apache/hadoop/util/ShutdownHookManager$2
at org.apache.hadoop.util.ShutdownHookManager.getShutdownHooksInOrder(ShutdownHookManager.java:124)
at org.apache.hadoop.util.ShutdownHookManager$1.run(ShutdownHookManager.java:52)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.ShutdownHookManager$2
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
請讓我知道需要做什麼。我嘗試添加一些,但沒有奏效。請建議。
我曾嘗試在現在和現在添加這些依賴關係,但它是相同的問題。我猜這個問題是因爲重複的依賴關係,而不是缺少依賴關係。 – thevillageguy
你能幫我理解一下,我添加的上述依賴關係是否增加了任何與log4j或番石榴有關的重複依賴關係? – thevillageguy
Jars與'artifactId-version'名稱一起打包,因此您包含在相同artifactId和版本中的任何依賴項只會包含一次。但是,你應該檢查你是否已經有了不同版本的log4j,如果你確實已經有'log4j-extra'版本更改爲你自己的log4j版本。 – 11thdimension