I have some jars in the current directory, all needing to be in the class path, so I want to use the wildcards convention for classpath. The command line is:
java.exe -classpath * org.python.util.jython args
However I get this error
Exception in thread "main" java.lang.NoClassDefFoundError: G:/repo/builds/jars/edu_mines_jtk/jar
Caused by: java.lang.ClassNotFoundException: G:.repo.builds.jars.edu_mines_jtk.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: G:/repo/builds/jars/edu_mines_jtk.jar. Program will exit.
If I manually expand the wildcard, with
java.exe -classpath edu_mines_jtk.jar;ij.jar;jython.jar;more-jars org.python.util.jython [args]
Then it works as expected.
What's wrong with my wildcards?
JRE 1.6.25 for Win7 64 bit
A pragmatic way: Class. forName("com. myclass") where com. myclass is a class that is inside (and only inside) your target jar; if that throws a ClassNotFoundException , then the jar is not on you current classpath.
Just remember that classpath never works recursively, so if you want to scan a subdirectory for jars you need to point it explicitly.
I found it, under Windows quotes around the wildcarded classpath are required.
But not required if you specify jars explicitly, explaining why the second command works.
Weird.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With