在类路径中使用通配符调用 java 失败
我在当前目录中有一些 jar,它们都需要位于类路径中,所以我想对类路径使用通配符约定。命令行是:
java.exe -classpath * org.python.util.jython args
出现此错误
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.
但是,如果我手动扩展通配符,则
java.exe -classpath edu_mines_jtk.jar;ij.jar;jython.jar;more-jars org.python.util.jython [args]
,然后它会按预期工作。
我的通配符出了什么问题?
适用于 Win7 64 位的 JRE 1.6.25
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,在 Windows 下,需要在通配符类路径周围加上引号。
但如果您显式指定 jars,则不需要,这解释了第二个命令起作用的原因。
诡异的。
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.