如何在类路径中使用通配符添加多个jar?
我一直在使用如此多的第三方库(jar 文件),以至于我的 CLASSPATH 完全混乱,因为我必须包含我使用的每个 jar 文件的路径。
我一直想知道是否有一种方法可以使用通配符(*)运算符(如 *.jar)将所有 jar 文件包含在文件夹中。 但它似乎不起作用。 有没有其他方法可以缩短目前在我的电脑上看起来像一篇文章;)的 CLASSPATH?
I have been using so many 3rd party libraries(jar files) that my CLASSPATH is completely messed up as i have to include the path for every single jar file that i use.
I've been wondering if there is a way to include all the jar files in a folder using wildcard(*) operator (like *.jar). But it seems to be not working. Is there any other way that can shorten the CLASSPATH that currently looks like an essay ;) on my PC?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自: http://java.sun.com/javase /6/docs/technotes/tools/windows/classpath.html
这应该在 Java6 中工作,不确定 Java5 是否有效
(如果看起来它没有按预期工作,请尝试添加引号。例如:
“foo/*”
)From: http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html
This should work in Java6, not sure about Java5
(If it seems it does not work as expected, try putting quotes. eg:
"foo/*"
)这适用于 Windows:
其中
%MAINCLASS%
当然是包含 main 方法的类。或者:
其中
%MAINJAR%
是通过其内部清单启动的 jar 文件。This works on Windows:
where
%MAINCLASS%
of course is the class containing your main method.Alternatively:
where
%MAINJAR%
is the jar file to launch via its internal manifest.Java 6 中引入了基本名称通配符; 即“foo/*”表示“foo”目录中的所有“.jar”文件。
在不支持通配符类路径的早期 Java 版本中,我求助于使用 shell 包装器脚本通过“通配符”模式并修改结果以在适当的点插入“:”字符来组装类路径。 这在 BAT 文件中很难做到......
Basename wild cards were introduced in Java 6; i.e. "foo/*" means all ".jar" files in the "foo" directory.
In earlier versions of Java that do not support wildcard classpaths, I have resorted to using a shell wrapper script to assemble a Classpath by 'globbing' a pattern and mangling the results to insert ':' characters at the appropriate points. This would be hard to do in a BAT file ...
如果您的意思是您有一个名为 CLASSPATH 的环境变量,我会说这是您的错误。 我用来开发 Java 的任何机器上都没有这样的东西。 CLASSPATH 与特定项目紧密相关,不可能有一个适用于所有项目的单一、正确的 CLASSPATH。
我使用 IDE 或 Ant 为每个项目设置 CLASSPATH。 我做了很多 Web 开发,因此每个 WAR 和 EAR 使用自己的 CLASSPATH。
它被 IDE 和应用服务器忽略。 为什么你有它? 我建议删除它。
If you mean that you have an environment variable named CLASSPATH, I'd say that's your mistake. I don't have such a thing on any machine with which I develop Java. CLASSPATH is so tied to a particular project that it's impossible to have a single, correct CLASSPATH that works for all.
I set CLASSPATH for each project using either an IDE or Ant. I do a lot of web development, so each WAR and EAR uses their own CLASSPATH.
It's ignored by IDEs and app servers. Why do you have it? I'd recommend deleting it.