问题
So, I was trying to run this command:
java -cp ./target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar storm.starter.ExclamationTopology
To run the ExclamationTopology class in ./storm/starter/ but it didn't work.
Then someone on SO suggested me to change the command to this:
java -cp ./target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/Users/xxx/storm-0.8.2/storm-0.8.2.jar:/Users/xxx/storm-0.8.2/lib/*:/Users/xxx/storm-0.8.2/conf/s torm.yaml storm.starter.ExclamationTopology
And it worked. So I thought that I just had to add those paths to the path variable and that would do it, so I changed my path and this is what it looks like now:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/xxx/storm-0.8.2/storm-0.8.2.jar:/Users/xxx/storm-0.8.2/lib/*:/Users/xxx/storm-0.8.2/conf/storm.yaml
But I still can't get the first command running. Can anyone please tell me why? What I basically want is to get the first command running; it just somehow needs the correct path set, right? I believe that's exactly what I've done.
EDIT:
This is the error returned in the first command:
$ java -cp ./target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar storm.starter.ExclamationTopology
Exception in thread "main" java.lang.NoClassDefFoundError: backtype/storm/topology/IRichSpout
Caused by: java.lang.ClassNotFoundException: backtype.storm.topology.IRichSpout
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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
回答1:
You'll need to add the storm dependencies to your classpath - it's currently not included because it is marked as 'provided' in the m2-pom.xml, change it to 'compile':
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.8.2</version>
<scope>compile</scope>
</dependency>
来源:https://stackoverflow.com/questions/16928884/why-can-i-run-this-file-packaged-by-maven-by-specifying-the-path-as-argument-but