Unable to run a Java program from shell ClassNotFoundException
I am trying to run a Java program from the bash shell. The program uses some 3rd party libs (mysql connector , amazon aws)
This is just a standard java program , not running on a J2EE server or anything complicated.
It always complains that it cannot find one of the classes in the third party libs (ClassNotFoundException) (If I remove references to this then it will complain about a different one).
This is confusing since I have checked that the location of the jar files containing the libs is in the classpath. I have also tried putting the libs in the same folder as the .class File I am trying to run to no avail.
I compiled the program using the javac command on the same computer and it had no problems finding the libraries , so I am confused as to开发者_如何学运维 why it cannot find them at runtime..
I also tried this from cmd under windows but got the same problem.
The only rational explaination I can find is that it is due to security restrictions in the JVM , in which case it would be good to know how to disable them for this program?
Thanks
Kind of what Bozho said but for jar files you have to call out the jar file by path AND name, just not the path to them. From what I gathered from your post you are only adding the path.
It would be better if you had put the commandline that you are using in the question. It is basically something like this java -classpath c:/libs/myjar.jar;c:/libs/myjar2.jar;c:/myclasses MyClass
where MyClass is your "main" java class the -classpath option is the list of areas where you want the runtime to look for dependencies. The .jar are jar files and the folder myclasses is a folder where you may have a .class files or other config information that the program may need.
I figured this out for Linux, it's java -classpath "/path/to/jar/myjar.jar:." MyClass
精彩评论