Main-Class没有写到jar的清单中 [英] Main-Class is not written to manifest of a jar
问题描述
当我使用以下任一方法从.class文件创建jar文件时:
when I create a jar file from .class files with either:
jar cmvf META-INF/MANIFEST.MF MyApp.jar * .class
jar cmvf META-INF/MANIFEST.MF MyApp.jar *.class
或
jar cmvf manifest.mf MyApp.jar * .class
jar cmvf manifest.mf MyApp.jar *.class
尽管清单文件中有与主类的一行:
despite a line with main class in the manifest file:
清单版本:1.0
Manifest-Version: 1.0
Created-By:1.8.0_171(Oracle公司)
Created-By: 1.8.0_171 (Oracle Corporation)
Main-Class:MainClassName
Main-Class: MainClassName
启动MyApp.jar时出现错误
I get an error when I start MyApp.jar
java -jar MyApp.jar
java -jar MyApp.jar
在MyApp.jar中没有主清单属性
no main manifest attribute, in MyApp.jar
当我用以下方法打开罐子的包装时(在其他文件夹中):
when i unpack the jar (in some other folder) with:
jar xf MyApp.jar
jar xf MyApp.jar
清单看起来像这样:
清单版本:1.0
Manifest-Version: 1.0
Created-By:1.8.0_171(Oracle公司)
Created-By: 1.8.0_171 (Oracle Corporation)
为什么主线消失了? "MainClassName.class";在此文件夹中,并且其中具有主要功能.这是我创建jar时的输出:
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:
添加清单
添加:SomeClass.class(输入= 1106)(输出= 472)(放气57%)
adding: SomeClass.class(in = 1106) (out= 472)(deflated 57%)
...其他课程...
... other classes ...
谢谢.
[解决方案] ,感谢戴夫
(特别是在Windows上)确保最后一行,在这里是Main-class:行,具有行终止符,也称为换行符(LF或CRLF).如果最后一行未终止,则将其忽略. (在清单的主要部分的末尾,实际上实际上应该有第二个换行符,因此为空行,但是IME可以在没有该换行符的情况下工作.)
(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.)
推荐答案
从Java 8开始,清单是在jar名称之后写的:
Starting in Java 8, the manifest is written after the jar name:
jar cmvf MyApp.jar META-INF/MANIFEST.MF *.class
这篇关于Main-Class没有写到jar的清单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!