我使用
https://stackoverflow.com/a/5893391/14731中的指令向Class-Path属性添加任意条目.这是我的MANIFEST.MF文件:
Manifest-Version: 1.0
Class-Path: jace-runtime.jar
Main-Class: org.jace.examples.Test
我定义了org.jace.examples.Test如下:
public class Test
{
public static void main(String[] args)
{
System.out.println("classpath: " + System.getProperty("java.class.path"));
System.out.println("PeerExample: " + Class.forName("org.jace.util.ShutdownHook"));
}
}
其中org.jace.util.ShutdownHook在jace-runtime.jar中定义.当我调用java -jar peer_example1.jar时,我得到以下输出:
classpath:peer_example1.jar
线程中的异常“main”java.lang.ClassNotFoundException:org.jace.util.ShutdownHook
换句话说,Java将可执行JAR文件添加到类路径,但忽略了Class-Path.如果我调用java -cp jace-runtime.jar; peer_example1.jar org.jace.examples.Test我得到预期的输出:
classpath:jace-runtime.jar; peer_example1.jar
有任何想法吗?