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 <code>path.separator</code>. This character is used to
* separate filenames in a sequence of files given as a <em>path list</em>.
* On UNIX systems, this character is <code>':'</code>; on Microsoft Windows systems it
* is <code>';'</code>.
*
* @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
classLoader的问题以后深揪,今天也算是长见识了。