问题
when I create a jar file from .class files with either:
jar cmvf META-INF/MANIFEST.MF MyApp.jar *.class
or
jar cmvf manifest.mf MyApp.jar *.class
despite a line with main class in the manifest file:
Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation)
Main-Class: MainClassName
I get an error when I start MyApp.jar
java -jar MyApp.jar
no main manifest attribute, in MyApp.jar
when i unpack the jar (in some other folder) with:
jar xf MyApp.jar
the manifest looks like this:
Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation)
why main class line disappears? "MainClassName.class" is in this folder and it has main function in it. Here is the output when i create the jar:
added manifest
adding: SomeClass.class(in = 1106) (out= 472)(deflated 57%)
... other classes ...
Thanks in advance.
[SOLUTION] thanks to dave
(Especially on Windows) Make sure the last line, here the Main-class: line, has a line terminator aka newline (LF or CRLF). If the last line is unterminated it is ignored. (Officially there should actually be a second newline, thus an empty line, at the end of the manifest main-section, but IME it works without that.)
回答1:
Starting in Java 8, the manifest is written after the jar name:
jar cmvf MyApp.jar META-INF/MANIFEST.MF *.class
Java 7
Java 8
来源:https://stackoverflow.com/questions/51368363/main-class-is-not-written-to-manifest-of-a-jar