1:初次運行Strom程序出現如下所示的錯誤,貼一下,方便腦補,也希望幫助到看到的小伙伴:
錯誤如下所示,主要問題是剛開始使用maven獲取jar包的時候需要寫<scope>provided</scope>,運行的時候需要把這行注釋了即可,這是作用域的問題,開始需要在本地下載jar包,但是在虛擬機運行的時候已經存在這些jar包了,所以再寫這句話就沖突了:
1 java.lang.NoClassDefFoundError: backtype/storm/topology/IRichSpout 2 at java.lang.Class.getDeclaredMethods0(Native Method) 3 at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) 4 at java.lang.Class.getMethod0(Class.java:2866) 5 at java.lang.Class.getMethod(Class.java:1676) 6 at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) 7 at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) 8 Caused by: java.lang.ClassNotFoundException: backtype.storm.topology.IRichSpout 9 at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 10 at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 11 at java.security.AccessController.doPrivileged(Native Method) 12 at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 13 at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 14 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 15 at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 16 ... 6 more 17 Exception in thread "main" 18 Process finished with exit code 1
解決方法如下所示:
貼下pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>com.bie</groupId> <artifactId>storm</artifactId> <version>1.0-SNAPSHOT</version> <!-- storm的依賴關系 --> <dependencies> <dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core</artifactId> <version>0.9.5</version> <!--<scope>provided</scope>--> </dependency> </dependencies> <!--如果依賴外部包,就打不進去外部包,所以需要引入下面所示--> <build> <plugins> <plugin> <!--把其他外部依賴的jar包打成一個大jar包--> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.bie.wordcount.WordCountTopologyMain</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
停更......