Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling java with wildcards in classpath fails

Tags:

java

classpath

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

like image 802
CharlesB Avatar asked May 30 '11 17:05

CharlesB


People also ask

How do I know if a jar is in classpath?

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.

Is Java classpath recursive?

Just remember that classpath never works recursively, so if you want to scan a subdirectory for jars you need to point it explicitly.


1 Answers

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.

like image 96
CharlesB Avatar answered Oct 12 '22 00:10

CharlesB