为什么无法从 JAR 文件加载主类清单属性? [英] Why has it failed to load main-class manifest attribute from a JAR file?
问题描述
我以这种方式创建了一个 JAR 文件 jar cf jar-file input-files
.现在,我正在尝试运行它.运行它不起作用(找不到jre命令):
I have created a JAR file in this way jar cf jar-file input-files
. Now, I'm trying to run it. Running it does not work (jre command is not found):
jre -cp app.jar MainClass
这也不起作用:
java -jar main.jar
(无法从 main.jar 加载主类清单属性).
(Failed to load Main-Class manifest attribute from main.jar).
我也发现了
运行打包为JAR 文件(版本 1.2 -- 需要主类清单头)
To run an application packaged as a JAR file (version 1.2 -- requires Main-Class manifest header)
什么是主类清单标头"?如何创建它以及将它放在哪里?
What is the "Main-Class manifest header"? How do I create it and where do I put it?
推荐答案
我不确定我是否相信你的症状:
I'm not sure I believe your symptoms:
- 如果没有找到
jre
命令,那么运行jre -cp app.jar
应该会给出同样的错误 - 只需将 JAR 文件添加到类路径中不会出现错误你看到了
- If the
jre
command isn't found, then runningjre -cp app.jar
should give the same error - Just adding a JAR file to the classpath shouldn't give the error you're seeing
如果您运行,我希望您会看到此错误:
I'd expect you to see this error if you run:
java -jar app.jar
Main-Class 标头需要在 JAR 文件的清单中 - 这是有关其他所需库等内容的元数据.请参阅 Sun 文档,了解如何创建适当的清单.基本上,您需要创建一个文本文件,其中包含如下一行:
The Main-Class header needs to be in the manifest for the JAR file - this is metadata about things like other required libraries. See the Sun documentation for how to create an appropriate manifest. Basically you need to create a text file which includes a line like this:
Main-Class: MainClass
然后运行
jar cfm app.jar manifest.txt *.class
这篇关于为什么无法从 JAR 文件加载主类清单属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!