Intellij Idea 使用Intellij和Maven时发现错误

x759pob2  于 2022-11-21  发布在  Maven
关注(0)|答案(3)|浏览(172)

我正在使用Maven 3.0.5和Intellij 14.0.2,Maven没有在我的项目的calsspath中复制所需的jar,所以我手动复制它,并试图执行我的项目的主类,它给我带来了以下错误:

java.lang.NoClassDefFoundError: backtype/storm/topology/IRichSpout
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getMethod0(Class.java:2937)
at java.lang.Class.getMethod(Class.java:1771)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

 Caused by: java.lang.ClassNotFoundException: 
backtype.storm.topology.IRichSpout
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

我知道这很常见,并发现了一堆的解决方案在StackOverflow,但没有一个是为我工作。任何帮助将不胜感激。
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.shc</groupId>
    <artifactId>storm-npos</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.shc</groupId>
<artifactId>npos-topology</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>npos-topology</name>
<url></url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <slf4j-version>1.7.2</slf4j-version>
    <storm.version>0.8.2</storm.version>
</properties>
<repositories>
    <repository>
        <id>projectrepo</id>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>file://${project.basedir}/../lib</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>jcc_license_cisuz</artifactId>
        <version>3.8.47</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc</artifactId>
        <version>3.8.47</version>
        <!-- <scope>system</scope> <systemPath>${project.basedir}/../lib/com/ibm/db2/jcc/db2jcc/3.8.47/db2jcc-3.8.47.jar</systemPath> -->
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc_license_cu</artifactId>
        <version>3.8.47</version>
        <!-- <scope>system</scope> <systemPath>${project.basedir}/../lib/com/ibm/db2/jcc/db2jcc_license_cu/3.8.47/db2jcc_license_cu-3.8.47.jar</systemPath> -->
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-email</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.3</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>mq</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>mqjms</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>mqetclient</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>dhbcore</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>connector</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jms_1.1_spec</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>storm</groupId>
        <artifactId>storm</artifactId>
        <version>${storm.version}</version>
        <!-- keep storm out of the jar-with-dependencies -->
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.mock-javamail</groupId>
        <artifactId>mock-javamail</artifactId>
        <version>1.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.flume</groupId>
        <artifactId>flume-ng-embedded-agent</artifactId>
        <version>1.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flume</groupId>
        <artifactId>flume-ng-core</artifactId>
        <version>1.4.0</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.flume</groupId>
        <artifactId>flume-ng-configuration</artifactId>
        <version>1.4.0</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.flume</groupId>
        <artifactId>flume-ng-node</artifactId>
        <version>1.4.0</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.netflix.astyanax</groupId>
        <artifactId>astyanax</artifactId>
        <version>1.56.43</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
        <!-- <exclusions> <exclusion> <groupId>org.apache.cassandra</groupId> 
            <artifactId>cassandra-all</artifactId> </exclusion> </exclusions> -->
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>
    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit</artifactId>
        <version>1.2.0.1</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cassandra</groupId>
                <artifactId>cassandra-all</artifactId>
            </exclusion>

            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>

        </exclusions>
    </dependency>
    <!-- <dependency> <groupId>org.apache.cassandra</groupId> <artifactId>cassandra-all</artifactId> 
        <version>2.0.0</version> </dependency> <dependency> <groupId>org.hectorclient</groupId> 
        <artifactId>hector-core</artifactId> <version>1.1-4</version> <exclusions> 
        <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> 
        </exclusion> <exclusion> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> 
        </exclusion> </exclusions> </dependency> -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>13.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_2.8.0</artifactId>
        <version>0.8.1</version>
    </dependency>

    <dependency>
        <groupId>org.xerial.snappy</groupId>
        <artifactId>snappy-java</artifactId>
        <version>1.0.4.1</version>
    </dependency>
    <dependency>
        <groupId>com.101tec</groupId>
        <artifactId>zkclient</artifactId>
        <version>0.2</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jopt-simple</groupId>
        <artifactId>jopt-simple</artifactId>
        <version>3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.2.4</version>
    </dependency>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>2.11.1</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>com.shc</groupId>
        <artifactId>npos-parser</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.mock-javamail</groupId>
        <artifactId>mock-javamail</artifactId>
        <version>1.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.0.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.27</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc</artifactId>
        <version>3.8.47</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc_license_cu</artifactId>
        <version>3.8.47</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>jcc_license_cisuz</artifactId>
        <version>3.8.47</version>
    </dependency>
    <dependency>
        <groupId>org.jasypt</groupId>
        <artifactId>jasypt</artifactId>
        <version>1.9.0</version>
    </dependency>
</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <plugins>
        <!-- bind the maven-assembly-plugin to the package phase this will create 
            a jar file without the storm dependencies suitable for deployment to a cluster. -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <!--<mainClass></mainClass> -->
                        <mainClass>shc.npostopology.replay.ReplayClient</mainClass>

                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-Dfile.encoding=ISO-8859-1</argument>
                    <argument>-classpath</argument>
                    <!-- automatically creates the classpath using all project dependencies, 
                        also adding the project build directory -->
                    <classpath />
                    <argument>shc.npostopology.topologydef.NPOSProdTopology</argument>
                </arguments>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>ISO-8859-1</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>
nom7f22z

nom7f22z1#

storm库的作用域是provided,这意味着在运行时您必须自己提供依赖项(通常在将应用程序部署到应用程序服务器且库已在appserver中时使用)。对于独立应用程序,请将作用域更改为compile(或者删除它,因为compile是默认的)。那么运行应用程序时JAR应该在类路径中。

d4so4syb

d4so4syb2#

这可能是因为您导入的是storm工件而不是storm-core

<dependency>
    <groupId>org.apache.storm</groupId>
    <artifactId>storm-core</artifactId>
    <version>0.9.4</version>
</dependency>
mlmc2os5

mlmc2os53#

在我的例子中,通过将Add dependencies with “provided” scope to classpath添加到IntelliJ运行配置(如IntelliJ docs中所述)修复了这个问题。

相关问题