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

In Linux, how to execute Java jar file with external jar files?

解决方案

Either use the -cp flag:

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

Or add a Class-Path: header to your jar's manifest (see Jigar's answer)

Note to others who answered with java -jar : The -jar flag deactivates the standard -cp flag and CLASSPATH environment variable, because it retrieves the classpath from the JAR manifest. Any answer that combines -jar and either -cp or $CLASSPATH will not work.

This information is well-hidden, but I finally found a reference:

-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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值