类路径中的多个 jar 不起作用
我在 stackoverflow 上看到了几个非常相似的问题,但没有遇到任何与我的问题完全匹配的问题。我有一个包含几个 .java 文件的文件夹,另一个包含两个 .jar 文件的文件夹。我需要在使用 javac 时包含两个 jar 文件,以便一次性编译整个项目:
$: javac -classpath .:~/myjardir/*.jar ~/myprojectdir/*.java
但是如果我这样做,则只有第一个 jar 被识别,并且依赖于第二个 jar 的所有内容都会抛出错误。令人惊讶的是,如果我单独编译每个程序,
$: javac -classpath .:~/myjardir/oneofthejars.jar ~/myprojectdir/file1.java
那么一切都会正常工作。我还在 Eclipse 中单独编译了该项目,只是为了测试代码和 jar。只有当我尝试在命令行中使用两个带有 -classpath
的 jar 时,才会出现错误。通配符条目应该在 JDK6 中工作,所以我在这里不知所措。
I have seen several very similar questions on stackoverflow, but haven't come across anything that exactly matches my problem. I have a folder with several .java files, and another folder with two .jar files. I need to include both the jar files while using javac so that the entire project gets compiled at one go:
$: javac -classpath .:~/myjardir/*.jar ~/myprojectdir/*.java
But if I do this, only the first jar is recognized, and everything that depends on the second jar throws an error. Surprisingly, if I compile each program separately,
$: javac -classpath .:~/myjardir/oneofthejars.jar ~/myprojectdir/file1.java
then everything works fine. I have also compiled the project separately in Eclipse just to test the code and the jars. It is only when I try to use both the jars with -classpath
in command line that I get the errors. Wildcard entries are supposed to work in JDK6, so I am at a loss here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类路径通配符的工作方式与 Unix shell 中不同。
*
表示目录中名为*.jar
的所有内容。因此,您不需要执行*.jar
,而只需执行*
。以下内容应该满足您的要求:请参阅 了解类路径通配符 在 Java SE 6文档。
The class path wildcards don't work like they do in the Unix shells. The
*
means everything named*.jar
in the directory. So you don't need to do*.jar
but just*
. The following should do what you want:See Understanding class path wildcards in the Java SE 6 documentation.
请参阅这里的答案,但这里是Java文档中的相关段落:
see the SO answer here but here's the relevant paragraph from the Java documentation:
如果您想要在类路径中包含多个内容,据我所知,您必须通过类路径分隔符将它们分开。所以 ./lib:/lib/mylib 在 unix 系统上是一个有效的类路径,我认为在 Windows 系统上等效的是 .\lib;\lib\mylib 。您不必指定每个文件,只需指定目录即可。
if you want multiple things in a classpath, you have to separate them by the classpath separator as far as I know. So ./lib:/lib/mylib would be a valid classpath on a unix system, I think the equivalent would be .\lib;\lib\mylib on a windows system. You don't have to specify every file, just the directories.