使用命令行工具构建.jar文件时如何添加它的依存关系? [英] How can I add a .jar file dependencies when building it with the command line tool?
问题描述
一个非常简单的问题.可以不使用Ant或Maven来完成吗? (也就是说,我专门指的是命令行工具)
Pretty straightforward question. Can it be done without the use of Ants or Maven? (And by that, I mean the command line tool specifically)
请注意,我不想创建uberjar,我只希望存档的单元知道"其外部依赖项在哪里.
Please notice that I don't want to create an uberjar, I just want the archived unit to "know" where its external dependencies are.
推荐答案
假设您正在谈论javac
的命令行调用,那么您正在谈论的是我可以提供库作为javac的参数来实现吗?编译期间的要求".
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".
man javac
的顶部条目说
-classpath classpath
Sets the user class path, overriding the user class path in the
CLASSPATH environment variable. If neither CLASSPATH or -class-
path is specified, the user class path consists of the current
directory. See Setting the Class Path for more details.
有效地,我怀疑您只需要说
Effectively I suspect you just need to say
javac -classpath path/to/library1.jar Main.java
这篇关于使用命令行工具构建.jar文件时如何添加它的依存关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!