无法从 abc.jar 加载主类清单属性

发布于 2024-10-06 14:11:27 字数 167 浏览 0 评论 0原文

嗨,

我使用 eclipse 创建了一个可运行的 .jar 文件,并使用 jdk1.4.2 对其进行了编译,我能够在 Windows 上完美运行它,但每当我在 unix 上运行它时,它会说“无法从 abc 加载主类清单属性。 jar” 为什么会这样

请帮助

Saurabh

HI,

I have created a runnable .jar file using eclipse and compiled it with jdk1.4.2, i am able to run it perfectly on windows but whenever i run it on unix it says "failed to load main-class manifest attribute from abc.jar" Why is it so

Please help

Saurabh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若沐 2024-10-13 14:11:27

我通常避免使用可执行 jar。假设,我们有一个类 com.example.MyClass ,它有 main 方法,那么“可执行 jar”的清单 (myapp.jar) 需要行

Main-Class: com.example.MyClass

然后你可以像这样启动应用程序

java -jar myapp.jar

除了一些类路径烦恼之外,这与“烦恼”非常相似

java -cp myapp.jar com.example.MyClass

:如果使用 -jar 选项运行应用程序,则类路径必须在清单中定义 - 它将忽略任何 CLASSPATH 条目或 -cp 属性。因此,如果您有依赖项,则必须将它们从清单类路径属性复制并粘贴到 -cp 属性:

java -cp myapp.jar;<other libs> com.example.MyClass

I usually avoid executable jars. Assuming, we have a class com.example.MyClass that has has main method, then the "executable jar"'s manifest (myapp.jar) needs the line

Main-Class: com.example.MyClass

Then you can start the application like this

java -jar myapp.jar

Apart from some classpath annoyances, this is pretty similiar to

java -cp myapp.jar com.example.MyClass

The "annoyance": if run the application with the -jar option, the classpath has to be defined in the manifest - it will ignore any CLASSPATH entry or -cp attribute. So if you have dependencies, you'll have to copy and paste them from the manifests classpath attribute to the -cp attribute:

java -cp myapp.jar;<other libs> com.example.MyClass
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文