Calling java with wildcards in classpath fails

喜欢而已 提交于 2019-12-04 20:20:03

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6179281/calling-java-with-wildcards-in-classpath-fails

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