5

通过加入classpath的形式实现命令行运行java程序时引入第三方jar包

 2 years ago
source link: https://lichuanyang.top/posts/65262/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

通过加入classpath的形式实现命令行运行java程序时引入第三方jar包

发表于

2017-05-03 更新于 2021-09-23

阅读次数: 313 Valine: 0

在命令行运行java程序时,如果想引入第三方jar包该怎么办呢。方法其实有很多,一般都是去折腾classloader.

这里介绍一种操作相对简单的方法,就是在运行之前把需要的jar包都加入到classpath中。

具体来说,就是写一个shell脚本,定义一个参数,可以就叫CLASSPATH, 也可以叫别的。

CLASSPATH=yourownjar.jar:xxx.jar:/xx/xx/xxx1.jar:”$CLASSPATH”

需要注意的是,自己写的主类所在的jar也要包含在自己定义的classpath中.

然后使用java -classpath命令运行即可:

java -classpath ${CLASSPATH} xx.Main


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK