带Redis的错误运行风暴:java.lang。NoClassDefFoundError:Lredis /客户/能/能

时间:2022-07-01 14:03:36

My Storm class uses Redis queue to collect data.

我的Storm类使用Redis队列来收集数据。

I tried to run my Storm jar by

我试图把我的风暴罐拉过去。

storm jar jar_file_name.jar Topology_name configuration_file

But I got the following exception:

但我有一个例外:

Exception in thread "main" java.lang.NoClassDefFoundError: Lredis/clients/jedis/Jedis;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
    at java.lang.Class.getDeclaredField(Class.java:1946)
    at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1659)
    at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:72)
    at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:480)
    at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:468)
    at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1133)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
    at backtype.storm.utils.Utils.serialize(Utils.java:77)
    at backtype.storm.topology.TopologyBuilder.createTopology(TopologyBuilder.java:111)
    at OutlierPredictor.main(OutlierPredictor.java:98)
 Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.Jedis
    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)

I have compiled using

我已经编译通过

javac -classpath $HADOOP_CORE:$HBASE_CLASSPATH:/usr/local/hadoop-  2.2.0/redis_jar/commons-pool-1.5.5.jar:/usr/local/hadoop-2.2.0/redis_jar/jedis-2.1.0.jar:/usr/local/apache-storm-0.9.2-incubating/lib/storm-core-0.9.2-incubating.jar -d dir_name/ dir_name/Javafile.java 

from command line.

从命令行。

I am executing this in a single node set up.

我在一个单独的节点中执行这个操作。

What is going wrong?

什么错了吗?

3 个解决方案

#1


1  

You need to package all your code and dependencies into a single jar.

您需要将所有代码和依赖项打包到一个jar中。

Refer to the Storm tutorial, Topologies section,

参考风暴教程,拓扑部分,

Running a topology is straightforward. First, you package all your code and dependencies into a single jar. Then, you run a command like the following:

运行拓扑非常简单。首先,将所有代码和依赖项打包到一个jar中。然后,运行如下命令:

storm jar all-my-code.jar backtype.storm.MyTopology arg1 arg2

风暴jar所有代码。jar backtype.storm。MyTopology __arg1最长

You may have to use some packaging tool like, OneJAR, JarJar or ANT and create a jar containing all your files and dependencies. Please refer to these SO posts

您可能需要使用一些打包工具,比如OneJAR、JarJar或ANT,并创建一个包含所有文件和依赖项的jar。请参考这些帖子。

  1. Merging Multiple Jars in to a Single Jar
  2. 将多个Jar合并到一个Jar中。
  3. Easiest way to merge a release into one JAR file
  4. 将一个版本合并到一个JAR文件的最简单方法。

#2


0  

Thank you John for the answer .

谢谢约翰的回答。

But I found another solution.

但我找到了另一个解决办法。

I did not included jedis-2.1.0.jar, commons-pool-1.5.5.jar in my $STORM_HOME/lib/

我没有包括jedi -2.1.0。commons-pool-1.5.5 jar。在我$ STORM_HOME / lib / jar

Note: this two files were there in the $REDIS_CORE.

注意:这两个文件在$REDIS_CORE中。

#3


0  

1)add jedis in dependency

1)添加能依赖

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
</dependency>

2)use assembly plugin to package all dependencies into one jar file

2)使用汇编插件将所有依赖项打包到一个jar文件中。

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>your main class</mainClass>
            </manifest>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>your main class</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

3) ignore storm-core in package

3)在包中忽略storm-core。

<dependency>
    <groupId>org.apache.storm</groupId>
    <artifactId>storm-core</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>

#1


1  

You need to package all your code and dependencies into a single jar.

您需要将所有代码和依赖项打包到一个jar中。

Refer to the Storm tutorial, Topologies section,

参考风暴教程,拓扑部分,

Running a topology is straightforward. First, you package all your code and dependencies into a single jar. Then, you run a command like the following:

运行拓扑非常简单。首先,将所有代码和依赖项打包到一个jar中。然后,运行如下命令:

storm jar all-my-code.jar backtype.storm.MyTopology arg1 arg2

风暴jar所有代码。jar backtype.storm。MyTopology __arg1最长

You may have to use some packaging tool like, OneJAR, JarJar or ANT and create a jar containing all your files and dependencies. Please refer to these SO posts

您可能需要使用一些打包工具,比如OneJAR、JarJar或ANT,并创建一个包含所有文件和依赖项的jar。请参考这些帖子。

  1. Merging Multiple Jars in to a Single Jar
  2. 将多个Jar合并到一个Jar中。
  3. Easiest way to merge a release into one JAR file
  4. 将一个版本合并到一个JAR文件的最简单方法。

#2


0  

Thank you John for the answer .

谢谢约翰的回答。

But I found another solution.

但我找到了另一个解决办法。

I did not included jedis-2.1.0.jar, commons-pool-1.5.5.jar in my $STORM_HOME/lib/

我没有包括jedi -2.1.0。commons-pool-1.5.5 jar。在我$ STORM_HOME / lib / jar

Note: this two files were there in the $REDIS_CORE.

注意:这两个文件在$REDIS_CORE中。

#3


0  

1)add jedis in dependency

1)添加能依赖

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
</dependency>

2)use assembly plugin to package all dependencies into one jar file

2)使用汇编插件将所有依赖项打包到一个jar文件中。

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>your main class</mainClass>
            </manifest>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>your main class</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

3) ignore storm-core in package

3)在包中忽略storm-core。

<dependency>
    <groupId>org.apache.storm</groupId>
    <artifactId>storm-core</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>