[英]How can I add a .jar file dependencies when building it with the command line tool?
很直接的問題。 不使用 Ants 或 Maven 可以做到嗎? (我指的是命令行工具)
請注意,我不想創建一個 uberjar,我只想讓存檔單元“知道”它的外部依賴項在哪里。
假設您正在談論javac
的命令行調用,您正在談論的是“我可以向 javac 提供庫作為 arguments 以滿足編譯期間的要求”。
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.
實際上我懷疑你只需要說
javac -classpath path/to/library1.jar Main.java
您可以通過META-INF/MANIFEST.MF
。 您可以像這樣將其他 jars 添加到類路徑中:
Manifest-Version: 1.0
Main-Class: org.domain.MyMainClass
Class-Path: lib/slf4j-log4j12-1.5.8.jar lib/slf4j-api-1.5.8.jar
我相信,它只有在您定義Main-Class
並像這樣啟動您的應用程序時才有效:
java -jar my-app.jar
另請注意,類路徑路徑與主 jar 相關。 所以在我的示例目錄結構中應該是這樣的:
我認為您正在尋找的是清單文件,請在此處查看更多詳細信息http://download.oracle.com/javase/tutorial/deployment/jar/downman.ZFC35FDC70D5FC67A269883A82ZC2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.