[英]Jar file not working properly?
I made a classic hello world program in java called Hello.java: 我在java中创建了一个名为Hello.java的经典hello world程序:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
and I compiled it: javac Hello.java
我编译了它:
javac Hello.java
then I made a manifest called manifest.txt: 然后我做了一个名为manifest.txt的清单:
Main-Class: Hello
I then said jar cfm myJar.jar manifest.txt Hello.class
and indeed it made a jar file 然后我说
jar cfm myJar.jar manifest.txt Hello.class
,实际上它创建了一个jar文件
but when I did java -jar myJar.jar
it said no main manifest attribute. 但是当我做了
java -jar myJar.jar
它说没有主要的清单属性。 Thanks in advance . 提前谢谢。
您必须修改META-INF / MANIFEST.MF并添加此行Main-Class:com.mypackage.YourClass
It should be like 应该是这样的
jar -cvfm myJar.jar manifest.txt com.mysample.work.Hello.class jar -cvfm myJar.jar manifest.txt com.mysample.work.Hello.class
v - verbose (optional) v - 详细(可选)
Check your Hello class has the correct package 检查你的Hello类是否有正确的包
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.