问题
I am attempting to run VLCJ test jar from command line. VLCJ requires two external JARs
- jna.jar
- platform.jar
If I put those jars in the same directory as the executable jar I am attempting to run, I can run it successfully. However if I put them in their own directory and do the following:
java -classpath "C:\Users\Constantin\workspace\Java Libraries\JNA" -jar executable.jar
It cannot find a class from the JNA libraries. I am very new to Java, and my searches are not revealing a possible answer. So I was hoping someone could help answer:
How do I debug this? Why is it not finding the jar? Am I doing something wrong with my -classpath?
Thank you in advance!
Constantin
回答1:
Include the jars explicitly, or by using a simple *
wildcard, but also include the executable jar. Specify the executable jar's main
class on the command line (it will be in the manifest).
java -classpath "C:\Users\Constantin\workspace\Java Libraries\JNA\*;executable.jar" com.foo.Bar
(Where com.foo.Bar
is the class containing the main
method, the app entry point.)
See the Java options docs -- once jar
is specified, all other classpath information is discarded and the jar you specify must contain all the user classes.
Unrelated, but I always try to avoid paths with spaces in them on Windows. Well, everywhere, but particularly when dealing with Java-related stuff. It should work, and generally does, but there are edge cases when it doesn't (I'm looking at you, some versions of some app servers).
来源:https://stackoverflow.com/questions/9439936/setting-classpath-still-cant-find-external-jar