2

在我引入以下 Maven 依赖项之前,我有一个运行良好的应用程序。

    <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>

引入以下依赖项后,jar 已正确构建,没有编译器异常,但在运行应用程序时,它失败并出现以下异常:

例外一:

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 "org.apache.hadoop.hdfs.PeerCache@3826c025" 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

请让我知道需要做什么。我也尝试添加一些,但没有奏效。请建议。

4

3 回答 3

0

你试过这个:

mvn clean install -U

-Uask maven 强制更新依赖项。

于 2016-08-16T18:25:39.710 回答
0

在您的 POM 中包含以下依赖项

<!-- https://mvnrepository.com/artifact/log4j/apache-log4j-extras -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>apache-log4j-extras</artifactId>
    <version>1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>19.0</version>
</dependency>

这些都丢失了,因此您会遇到异常。

以下是 STS 中 POM 编辑器依赖项选项卡的屏幕截图。最新的eclipse也应该有。

在此处输入图像描述

您还可以使用以下命令检查依赖关系。

mvn dependency:tree
于 2016-08-16T18:29:13.610 回答
0

我接受了上面的答案,因为用户向我解释了一种识别添加的重复依赖项的方法。

这实际上是来自 POM 和运行时环境的重复 hadoop 依赖项的问题。

于 2016-09-12T20:17:49.873 回答