gpt4 book ai didi

java - 在Linux中,如何用外部jar文件执行Java jar文件?

转载 作者:IT王子 更新时间:2023-10-29 00:17:07 26 4
gpt4 key购买 nike

在Linux中,如何用外部jar文件执行Java jar文件?

最佳答案

要么使用 -cp标志:

java -cp /path/to/somefolder/*.jar:/path/to/otherfolder/*.jar com.YourMainClass

或者添加一个Class-Path: header 到您的 jar list (请参阅 Jigar 的回答)


请注意给其他回答 java -jar <etc> 的人: -jar标志停用标准 -cp标志和 CLASSPATH环境变量,因为它从 JAR list 中检索类路径。结合 -jar 的任何答案或者-cp$CLASSPATH将不起作用。

这个信息隐藏的很好,但我终于找到了一个引用:

-jar
Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[]
args)
method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests. When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

来源: java - the Java application launcher

关于java - 在Linux中,如何用外部jar文件执行Java jar文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5879925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com