Why can I run this file packaged by Maven by specifying the path as argument but not by setting the path permanently in my path variable?

断了今生、忘了曾经 提交于 2019-12-11 16:15:46

问题


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/s​torm.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!