Setting Classpath Still Can't Find External Jar
Asked Answered
S

1

1

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

Shannon answered 25/2, 2012 at 0:23 Comment(2)
@RanRag No; as per Java options, once -jar is specified, all other classpath settings will be ignored.Henchman
@DaveNewton: thanks removed my comment.Cooperage
H
6

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

Henchman answered 25/2, 2012 at 0:32 Comment(3)
Hey Dave, I examined the Java options doc. Thank you for the link. I extracted the META-INF/MANIFEST.MF and it's setting a classpath. Is this classpath going to be overwritten, or is it the one doing the overwriting? What options do I use to include all the jar files and set the main class?Shannon
@Shannon Honestly, not sure--if the jar sets its own classpath it'll probably use that one. If it includes the jars in question it may be enough to put them where the executable jar expects them... but not really sure, I'd have to try it.Henchman
I got it! java -cp "C:\Users\Constantin\...\JNA\*;C:\Users\Constantin\...\vlcj\vlcj-1.2.2-test.jar" uk.co.caprica.vlcj.test.basic.TestPlayerShannon

© 2022 - 2024 — McMap. All rights reserved.