我尝试创建一个简单的可执行jar文件。我的步骤是:
Test.java
public class Test{
public static void main(String[] args){
System.out.println("Hello World");
}
}
终端:
javac Test.java
生成Test.class
检查:
java Test
Hello World
创建manifest.mf文件:
Main-Class: Test
然后
jar -cfmv Test.jar manifest.mf Test.class
added manifest
adding: Test.class(in = 413) (out= 287)(deflated 30%)
最后
java -jar Test.jar
no main manifest attribute, in Test.jar
我按照Katanas的所有步骤回答:How to create a .jar file using the terminal
更新
根据ScaryWombat的建议,我解压缩了jar文件:
ls -alR
.:
total 16
drwxrwxr-x 3 infiniteZero infiniteZero 4096 May 28 02:25 .
drwxrwxr-x 4 infiniteZero infiniteZero 4096 May 28 02:26 ..
drwxrwxr-x 2 infiniteZero infiniteZero 4096 May 28 02:19 META-INF
-rw-rw-r-- 1 infiniteZero infiniteZero 413 May 28 01:50 Test.class
./META-INF:
total 12
drwxrwxr-x 2 infiniteZero infiniteZero 4096 May 28 02:19 .
drwxrwxr-x 3 infiniteZero infiniteZero 4096 May 28 02:25 ..
-rw-rw-r-- 1 infiniteZero infiniteZero 94 May 28 02:19 MANIFEST.MF
cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: Test.class
Created-By: 9-internal (Oracle Corporation)
答案 0 :(得分:0)
在清单末尾添加一个空行,重新编译并运行。你为编译器提供的清单应该是UTF-8
或: