测试完了 查看SUN的文档资料 http://java.sun.com/j2se/1.4.1/docs/guide/jar/jar.html#Manifest Specification 发现Class-Path只能用相对URL,多个URL之间用空格分割 Class-Path : 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实际测试结果也是如此,把mm.mysql-2.0.2-bin.jar 和Test.jar放在同一个盘符下 Manifest.mf的Class-Path内容 上一层Class-Path: ..\mm.mysql-2.0.2-bin.jar 同层Class-Path: mm.mysql-2.0.2-bin.jar 下一层Class-Path: subdirectory\mm.mysql-2.0.2-bin.jar这样运行java -jar Test.jar 都可以通过 就是说把mm.mysql-2.0.2-bin.jar 和Test.jar放在同一个盘符下就可以达到共用mm.mysql-2.0.2-bin.jar的目的可还是有盘符限制,如果用LINUX/UNIX系统那就可以无限制了
如果com是你的包的话
jar -cvfm Hello.jar mainfest.mf *.class
java -jar Hello.jar
--Exception in thread "main" java.lang.NoClassDefFoundError: Hellomainfest.mf里加上:
Class-Path: Help.jar
--没有效果,出错情况不变java -jar Hello.jar的话你要在Hello.jar的MANIFEST.MF中加上Main-Class: ...
--已经加了,程序可以运行,就是用到Help.jar里面的类的地方不正常
但是其他的多个程序也需要Help.jar,有没有办法通过某种配置实现Help.jar只留一份而其他的jar程序可以共享它呢?
就像在没将程序打包成jar之前可以通过配置Help.jar的完整路径到classpath来实现Help.jar的共享
多谢了
只有Help.jar和Test.jar在同一目录下才可以
[email protected]
//Test.java
public class Test
{
public static void main(String args[]) throws ClassNotFoundException
{
System.out.println("begin");
Class.forName("org.gjt.mm.mysql.Driver");
System.out.println("end");
}
}
从以下地址下载mm.mysql-2.0.2-bin.jar
http://mir.indymedia.org/cvs/viewcvs.cgi/*checkout*/mir/lib/Attic/mm.mysql-2.0.2-bin.jar将Test.java编译成Test.class,再把mm.mysql-2.0.2-bin.jar的完整路径加到系统classpath里面,就可以运行了
但是如果再把Test.class打包成Test.jar运行java -jar Test.jar,运行会报异常,除非把mm.mysql-2.0.2-bin.jar和Test.jar放在同一目录下
MANIFEST.MF内容如下Manifest-Version: 1.0
Created-By: 1.4.0_01 (Sun Microsystems Inc.)
Main-Class: Test
Class-Path: mm.mysql-2.0.2-bin.jar
//Test.java
public class Test
{
public static void main(String args[]) throws ClassNotFoundException
{
System.out.println("begin");
Class.forName("org.gjt.mm.mysql.Driver");
System.out.println("end");
}
}
从以下地址下载mm.mysql-2.0.2-bin.jar
http://mir.indymedia.org/cvs/viewcvs.cgi/*checkout*/mir/lib/Attic/mm.mysql-2.0.2-bin.jar将Test.java编译成Test.class,再把mm.mysql-2.0.2-bin.jar的完整路径加到系统classpath里面,就可以运行了
但是如果再把Test.class打包成Test.jar运行java -jar Test.jar,运行会报异常,除非把mm.mysql-2.0.2-bin.jar和Test.jar放在同一目录下
MANIFEST.MF内容如下Manifest-Version: 1.0
Created-By: 1.4.0_01 (Sun Microsystems Inc.)
Main-Class: Test
Class-Path: mm.mysql-2.0.2-bin.jar
只有mm.mysql-2.0.2-bin.jar 和 Test.jar放在同一目录下才可以
有没有办法通过某种配置实现mm.mysql-2.0.2-bin.jar只留一份而其他的jar程序可以共享它呢?
查看SUN的文档资料
http://java.sun.com/j2se/1.4.1/docs/guide/jar/jar.html#Manifest Specification
发现Class-Path只能用相对URL,多个URL之间用空格分割
Class-Path :
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实际测试结果也是如此,把mm.mysql-2.0.2-bin.jar 和Test.jar放在同一个盘符下
Manifest.mf的Class-Path内容
上一层Class-Path: ..\mm.mysql-2.0.2-bin.jar
同层Class-Path: mm.mysql-2.0.2-bin.jar
下一层Class-Path: subdirectory\mm.mysql-2.0.2-bin.jar这样运行java -jar Test.jar 都可以通过
就是说把mm.mysql-2.0.2-bin.jar 和Test.jar放在同一个盘符下就可以达到共用mm.mysql-2.0.2-bin.jar的目的可还是有盘符限制,如果用LINUX/UNIX系统那就可以无限制了