无法执行jar文件:“无主清单属性”

本文翻译自:Can't execute jar- file: “no main manifest attribute”

I have installed an application, when I try to run it (it's an executable jar) nothing happens. 我已经安装了一个应用程序,当我尝试运行它(它是一个可执行的jar)时,什么也没发生。 When I run it from the commandline with: 当我从命令行使用以下命令运行它时:

java -jar "app.jar" java -jar“ app.jar”

I get the following message: 我收到以下消息:

no main manifest attribute, in "app.jar" 在“ app.jar”中没有主清单属性

Normally, if I had created the program myself, I would have added a main class attribute to the manifest file. 通常,如果我自己创建了程序,则应该在清单文件中添加一个main class属性。 But in this case, since the file is from an application, i cannot do that. 但是在这种情况下,由于文件来自应用程序,因此我无法做到这一点。 I also tried extracting the jar to see if I could find the main class, but there are to many classes and none of them has the word "main" in it's name. 我还尝试提取jar,以查看是否可以找到主类,但是有很多类,但它们中的任何一个都没有名称“ main”。 There must be a way to fix this because the program runs fine on other systems. 由于该程序可以在其他系统上正常运行,因此必须有一种解决方法。


#1楼

参考:https://stackoom.com/question/eekz/无法执行jar文件-无主清单属性


#2楼

Any executable jar file Should run either by clicking or running using command prompt like java -jar app.jar (use "if path of jar contains space" - ie java -jar "C:\\folder name\\app.jar"). 任何可执行的jar文件都应通过单击来运行,或者通过使用命令提示符运行,如java -jar app.jar(使用“如果jar的路径包含空格”,即java -jar“ C:\\ folder name \\ app.jar”)运行。 If your executable jar is not running, which means it is not created properly. 如果您的可执行jar未运行,则表示未正确创建它。

For better understanding, extract the jar file (or view using any tool, for windows 7-Zip is nice one) and check the file under /META-INF/MANIFEST.MF. 为了更好地理解,请解压缩jar文件(或使用Windows 7-Zip的任何工具进行查看),然后在/META-INF/MANIFEST.MF下检查该文件。 If you find any entry like 如果您发现任何类似的条目

Main-Class: your.package.name.ClaaswithMain - then it's fine, otherwise you have to provide it. Main-Class:your.package.name.ClaaswithMain-那么就可以了,否则您必须提供它。

Be aware of appending Main-Class entry on MANIFEST.MF file, check where you are saving it! 请注意在MANIFEST.MF文件上附加Main-Class条目,请检查保存位置!


#3楼

For maven, this is what solved it (for me, for a Veetle codebase on GitHub): 对于maven,这就是解决问题的方法(对我来说,对于GitHub上的Veetle代码库):

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.0</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>org.lazydevs.veetle.api.VeetleAPI</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
 </plugins>
</build>

Cheers... 干杯...


#4楼

尝试以下命令以包含jar:

java -cp yourJarName.jar your.package..your.MainClass

#5楼

You might not have created the jar file properly: 您可能没有正确创建jar文件:

ex: missing option m in jar creation 例如:jar创建中缺少选项m

The following works: 以下作品:

jar -cvfm MyJar.jar Manifest.txt *.class

#6楼

You Can Simply follow this step Create a jar file using 您可以简单地按照以下步骤使用创建一个jar文件

 jar -cfm jarfile-name manifest-filename Class-file name

While running the jar file simple run like this 在运行jar文件时,像这样简单运行

 java -cp jarfile-name main-classname
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值