无法加载Main-Class清单属性 [英] Failed to load Main-Class manifest attribute

查看:135
本文介绍了无法加载Main-Class清单属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常常见的问题,但我尝试使用谷歌搜索并没有得到任何有用的结果。
我正在尝试用我的Main.class文件制作一个jar(在NetBeans中制作,但我不是想用它制作jar)

I know this is a very common question, but I tried googling and got no helpful result. I'm trying to make a jar out of my "Main.class" file (made in NetBeans, but I'm not trying to make the jar with it)

我运行了这个命令:

D:\NetBeans\trovanum3\build\classes\trovanum3>jar cf trovanum.jar *.class

并在该文件夹中生成一个.jar文件。我认为那会有效,但它不会运行。

And a .jar file spawned in that folder. I thought that would've worked, but it won't run.

我尝试用存档开启器打开jar文件,里面是Main.class文件和包含名为MANIFEST.MF的文件的META-INF文件夹
该文件包含:

I tried opening the jar file with an archive opener and inside it are the "Main.class" file and a "META-INF" folder containing a file named "MANIFEST.MF" The file contains this:

Manifest-Version: 1.0
Created-By: 1.6.0_22 (Sun Microsystems Inc.)

可能是什么问题?

推荐答案

你可以使用 -e jar 选项以指定条目点,即主类。例如:

You can use the -e option of jar to specify the entry point, i.e. the main class. For example:

D:\NetBeans\trovanum3\build\classes> jar cfe trovanum.jar trovanum3.Main trovanum3\*.class

如果这是清单,可以摆弄清单所有你需要的东西。请注意,您的问题中引用的工作目录一个。否则,Main类是在jar的顶层创建的,而不是在反映它应该驻留的包的目录中。 jar -tvf 然后应显示如下内容:

Saves fiddling with the manifest if that's all you need in there. Note the working directory is one up from that quoted in your question. Otherwise the Main class is created at the top-level in the jar, rather than in a directory that reflects the package in which it should reside. jar -tvf should then show something like this:

  0 Thu Oct 21 22:34:30 BST 2010 META-INF/
 80 Thu Oct 21 22:34:30 BST 2010 META-INF/MANIFEST.MF
488 Thu Oct 21 22:18:24 BST 2010 trovanum3/Main.class




-e

-e

将入口点设置为捆绑到可执行
jar文件中的独立
应用程序的应用程序
入口点。使用此选项
会在清单文件中创建或覆盖Main-Class
属性值。
此选项可在
创建jar文件期间或在更新
jar文件时使用。此选项指定
没有
编辑或创建清单文件的应用程序入口点。

Sets entrypoint as the application entry point for stand-alone applications bundled into executable jar file. The use of this option creates or overrides the Main-Class attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.

这篇关于无法加载Main-Class清单属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆