“无主要清单属性"在 ----.jar 中 [英] "No Main Manifest Attribute" in ----.jar Netbeans

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

问题描述

我最近刚开始在 java 中玩弄 Maven.是时候测试我的项目了,它在 NetBeans 窗口中运行良好,运行在 App.java (com.MyCompany.App) 中找到的主类,但是当我尝试从命令行运行它时出现错误:

java -jar 文件名.jar

<块引用>

fileName.jar 中的No Main Manifest Attribute"

我尝试添加一个 manifest.mf 文件来指定 main 是什么,我也已经进入项目属性并将其添加为主文件...

怎么回事?

解决方案

希望您的清单文件中存在问题.一些基本检查可能会解决您的问题.

  • 它应该在/META-INF/MANIFEST.MF
  • 内容应该有 Main-Class:com.MyCompany.App

如果您使用任何 IDE,应该有一个选项可以将项目导出为 runnable jar,您可以利用它让 IDE 处理正确的清单.

从命令行 jar cfm filename.jar Manifest.txt com/MyCompany/*.class 生成具有以下内容的 Manifest 文件

清单版本:1.0创建者:1.6.0(Sun Microsystems Inc.)主类:com.MyCompany.App

然后你可以运行jar命令java -jar fileName.jar.

这些类型的问题是微不足道的,但会浪费很多时间,只要确保您的文件内容和位置正确即可.

I recently just started toying around with Maven in java. Time comes to test my project, it works fine in the NetBeans window, running the main class found in App.java (com.MyCompany.App), but when I try to run it from a command line I get an error:

java -jar fileName.jar

"No Main Manifest Attribute" in fileName.jar

I have tried adding a manifest.mf file specifying what main is, I've also been into project properties and added it as the main file...

What's going on?

解决方案

Hope there is a problem in your manifest file. Some basic checks might solve your problem.

  • it should under /META-INF/MANIFEST.MF
  • Content should have Main-Class:com.MyCompany.App

If you are using any IDE, there should be an option to export project as runnable jar, you can make use of that to let the IDE take care of correct manifest.

From command line jar cfm filename.jar Manifest.txt com/MyCompany/*.class which generates the Manifest file with following contents

Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: com.MyCompany.App

And then you can run jar command java -jar fileName.jar.

These type of problems are trivial but kills lot of time, just ensure your contents and location of the file is correct.

这篇关于“无主要清单属性"在 ----.jar 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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