显示“无法从 TestExample.jar 加载主类清单属性”
Failed to load Main-Class manifest attribute from TestExample.jar
当我尝试运行可执行jar文件时如何解决上述问题?
Failed to load Main-Class manifest attribute from TestExample.jar
How to resolve the above problem of when I am trying to run the executable jar file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否在指定
Main-Class
的 jar 中包含了META-INF
文件?命令:
jar cvfm MyJarName.jar manifest.txt *.class
cvfm 的意思是“创建一个 jar;显示详细输出;指定输出 jar 文件名;指定清单文件名。”
Did you include the
META-INF
file in the jar which specifies theMain-Class
?Command:
jar cvfm MyJarName.jar manifest.txt *.class
cvfm means "create a jar; show verbose output; specify the output jar file name; specify the manifest file name."
您需要在 Manifest 中指定主类。这就是指定 jar 入口点的方式。您在此处指定的类需要有一个 main 方法,该方法在运行 jar 时首先执行。
看一下这个以获得很好的解释: http://docs.oracle .com/javase/tutorial/deployment/jar/appman.html
You need to specify the main class in the Manifest. This is how you specify the entry point into the jar. The class you specify here needs to have a main method which is executed first when running the jar.
Take a look at this for a good explanation: http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Java 有两种方法来启动 JAR 文件。第一个指定 JAR 文件和主类(具有静态
main(String[])
方法的类):第二个方法使用
-jar
参数(而不是-classpath
参数)。它不允许指定主类:相反,它希望在 清单。 (META-INF/MANIFEST.MF
包含一行Main-Class: com.example.Main
)。您的错误消息意味着您有一个 JAR 文件,该文件未构建为可执行 JAR 文件(没有主类的清单条目)。您要么需要以不同的方式构建 JAR,要么使用命令行的第一个变体启动它。顺便说一句:当您双击带有
*.jar
文件扩展名的文件时,通常会使用第二种变体。Java has two methods to start with a JAR file. The first one specifies the JAR file and the main class (the class with the static
main(String[])
method):The second method uses the
-jar
parameter (instead of the-classpath
parameter). It does NOT allow to specify the main class: instead it expects the main class to be specifies inside of the JAR file in the Manifest. (META-INF/MANIFEST.MF
containing a lineMain-Class: com.example.Main
).Your Error message means you have a JAR file which is not constructed as an executable JAR file (no manifest entry for the main class). You either need to build the JAR differently or start it with the first variant of the command line. BTW: the second variant is often used when you double click a file with the
*.jar
file extension.