在类路径中使用通配符调用Java失败 [英] Calling java with wildcards in classpath fails

查看:77
本文介绍了在类路径中使用通配符调用Java失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在当前目录中有一些jar,所有的jar都需要放在类路径中,因此我想对类路径使用通配符约定。命令行为:

  java.exe -classpath * org.python.util.jython args 

但是我收到此错误

 线程主中的异常java.lang.NoClassDefFoundError:G:/ repo / builds / jars / edu_mines_jtk / jar 
原因:java.lang.ClassNotFoundException:G:.repo.builds.jars.edu_mines_jtk.jar
在java.net.URLClassLoader $ 1.run(未知源)
在java.security.AccessController.doPrivileged(本机方法)
在java.net.URLClassLoader.findClass(未知源)
在java.lang.ClassLoader.loadClass(未知来源)
在sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)
在java.lang.ClassLoader.loadClass(未知来源)
找不到主类:G:/repo/builds/jars/edu_mines_jtk.jar。程序将会退出。

如果我手动扩展通配符,则使用

  java.exe -classpath edu_mines_jtk.jar; ij.jar; jython.jar; more-jars org.python.util.jython [args] 

然后按预期运行。



通配符怎么了?



用于Win7 64位的JRE 1.6.25

解决方案

必须在通配符的类路径周围使用Windows引号。



但如果您明确指定jar,则不需要这样做,解释第二个命令为何起作用。



很奇怪。 p>

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

解决方案

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.

这篇关于在类路径中使用通配符调用Java失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆