java jar classpath
突然被测试同学问到一个jar 运行的问题,之前一直没关注过jar的依赖设置,这里记录下。
JAR 文件揭密
http://www.ibm.com/developerworks/cn/java/j-jar/index.html
里面提到一点很重要的:(傻傻的一直还cp设置了半天)
一个可执行的 JAR 必须通过 menifest 文件的头引用它所需要的所有其他从属 JAR。如果使用了 -jar 选项,那么环境变量 CLASSPATH 和在命令行中指定的所有类路径都被 JVM 所忽略。
Adding Classes to the JAR File's Classpath
http://download.oracle.com/javase/tutorial/deployment/jar/downman.html
jar doc
http://download.oracle.com/javase/1.5.0/docs/guide/jar/jar.html#Manifest%20Specification
重要的点是:
The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path.