使用命令行工具构建时如何添加 .jar 文件依赖项?
非常简单的问题。不使用Ants或Maven可以完成吗? (我特指的是命令行工具)
请注意,我不想创建 uberjar,我只是希望存档单元“知道”其外部依赖项在哪里。
Pretty straightforward question. Can it be done without the use of Ants or Maven? (And by that, I mean the command line tool specifically)
Please notice that I don't want to create an uberjar, I just want the archived unit to "know" where its external dependencies are.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您正在谈论
javac
的命令行调用,那么您正在谈论的是“我可以提供库作为 javac 的参数来满足编译期间的要求”。man javac
的顶部条目说实际上,我怀疑你只需要说
javac -classpath path/to/library1.jar Main.java
Presuming you're talking about a command line invocation of
javac
, what you're talking about is "can I provide libraries as arguments to javac to fulfill requirements during compilation".Top entry for
man javac
saysEffectively I suspect you just need to say
javac -classpath path/to/library1.jar Main.java
您可以通过
META-INF/MANIFEST.MF
来实现。您可以像这样将其他 jar 添加到类路径中:我相信,只有在定义 Main-Class 并像这样启动应用程序时它才有效:
另请注意,类路径路径是相对于主 jar 的。因此,在我的示例中,目录结构应如下所示:
You can make it through
META-INF/MANIFEST.MF
. You can add other jars to the classpath like this:I believe, that it works only if you define
Main-Class
and start your application like this:Also notice, that classpath paths are relative to the main jar. So in my example directory structure should look like this:
我认为您正在寻找的是清单文件,请在此处查看更多详细信息
http://download.oracle.com/javase/tutorial/deployment/jar /downman.html
I think what you are looking for is a manifest file, Look here for more details
http://download.oracle.com/javase/tutorial/deployment/jar/downman.html