Setting Classpath Still Can't Find External Jar

一笑奈何 提交于 2019-12-11 07:14:14

问题


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

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