Setting Classpath Still Can't Find External Ja

2019-08-10 11:28发布

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

标签: java vlcj
1条回答
叛逆
2楼-- · 2019-08-10 11:41

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).

查看更多
登录 后发表回答