Java怎么知道能不能运行_你知道怎么运行java吗

1. runnable jar

选择主类后打成jar包

MANIFEST.MF是这样的

Manifest-Version: 1.0

Class-Path: .

Main-Class: com.dic.helloworld.Main

运行 直接 java -jar   jar包名就可以

2.  -cp  -classpath 这种方式

今天由于自己学艺不精 被坑的非常严重

-classpath  与-cp 一样,将jar包配上即可,如 -cp ./lib/*.jar 怎么样,这样这样是不可以的,classpath jar包和jar包之间有个东西还记得吗? linux下为  :  windows下为 ;

这是什么呢,看文档 永远都是最好的选择

/**

* The system-dependent path-separator character.  This field is

* initialized to contain the first character of the value of the system

* property path.separator.  This character is used to

* separate filenames in a sequence of files given as a path list.

* On UNIX systems, this character is ':'; on Microsoft Windows systems it

* is ';'.

*

* @see     java.lang.System#getProperty(java.lang.String)

*/

public static final char pathSeparatorChar = fs.getPathSeparator();

所以如果一个目录下你有很多jar包要加载 而且你又要是用-cp这种方式,那么问题来了,该怎么写

LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`

我只知道linux环境下怎么写哦,把这个目录下的jar文件全部放在classpath而且两个jar之间必须是有   File.pathSeparatorChar才可以。这样就可已运行了,

3.另外一种方式 就是  -Djava.ext.dirs=./lib/  只要指定jar文件的路径就可已

然后看一下classloader

4ea37c039d5b7c5881af6133625d8d52.png

classLoader的问题以后深揪,今天也算是长见识了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值