java.lang.NoClassDefFoundError

时间:2015-10-26 10:40:28

标签: java maven apache-storm

这是编译项目时的结果

通过此命令

mvn compile exec:java -Dexec.classPathScope=compile -Dexec.mainClass=trident.myproject

得到了这个

java.lang.NoClassDefFoundError: storm/trident/state/StateFactory
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getMethod0(Class.java:2670)
at java.lang.Class.getMethod(Class.java:1603)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:662)
 Caused by: java.lang.ClassNotFoundException: storm.trident.state.StateFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more

INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]   ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. storm/trident  /state/StateFactory

storm.trident.state.StateFactory

我查看了该文件夹,找不到这个课程!虽然我成功地运行了

我把pom文件写成了部分

<dependencies>
        <dependency>
            <groupId>storm</groupId>
            <artifactId>storm</artifactId>
            <version>0.8.2</version>
            <scope>provided</scope>
        </dependency>

pom.xml的第2部分

<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>colt</groupId>
        <artifactId>colt</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.0.0</version>
    </dependency>

pom.xml的第3部分

<dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-core</artifactId>
        <version>4.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-stream</artifactId>
        <version>4.0.2</version>
    </dependency>
            <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.17</version>
            </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:1)

您可能已在pom.xml文件中更改了依赖项的范围。如果您的容器正在提供依赖项更改范围 <scope>provided</scope>

如果容器未提供依赖项更改范围以进行编译 <scope>compile</scope>