我有以下步骤:
(1)我在/ home / a的Linux主目录下
(2)一个简单的Java文件cat m.java
package my;
public class m{
public static void main(String[] args){
}
}
(3)javac m.java
(4)mkdir我&& cp m.class我/
(5)$cat manifest.mf
Manifest-Version: 1.0
Main-Class: my/m
Class-Path: /home/a
(6)jar cfm m.jar manifest.mf m.class
(7)java -jar m.jar
Error: Could not find or load main class m.class
如何使其运作?
解决方法:
Main-Class应该与点分开的包一起使用,而不是/
Main-Class: my.m
Main-Class: MyPackage.MyClass
如果您不需要更多的罐子,则删除Class-Path行
Adding Classes to the JAR File’s Classpath
You may need to reference classes in other JAR files from within a JAR file.