简体   繁体   English

在NetBeans中构建可执行JAR无效

[英]Building executable JAR in NetBeans not working

I have seen a lot of references to this type of problem on StackOverflow and other places on the internet but the solution everybody else is happy with isn't working for me. 我在StackOverflow和互联网上的其他地方看到了很多关于此类问题的参考,但是其他人都满意的解决方案对我来说并不奏效。

The issue: I've created Java projects and would like to run them via executable .jar files. 问题:我已经创建了Java项目,并希望通过可执行的.jar文件运行它们。 When I try to run a .jar file for my project I get a "Could not find the main class: classname. Project will exit." 当我尝试为我的项目运行.jar文件时,出现“找不到主类:类名。项目将退出”。 error. 错误。

Solutions I've read about: 我读过的解决方案:
-editing the 'main class' from the project properties "run" tab and choose the location of the main class. 在项目属性“运行”选项卡中编辑“主类”,然后选择主类的位置。
-edit the manifest file to include: Main-Class: classname -编辑清单文件以包括:Main-Class:类名

None of this has worked. 这些都不起作用。 Entering the right class in the project properties, and with an updated manifest file I still get the main class not found error and I have run out of ideas on how to fix this. 在项目属性中输入正确的类,并使用更新的清单文件,我仍然会遇到未找到主类的错误,并且我已经没有足够的想法来解决此问题。

Any help would be more than slightly appreciated. 任何帮助将不胜感激。

EDIT: 编辑:

Here is a copy of my actual manifest file in its entirity: 这是我的清单文件的完整副本:

Manifest-Version: 1.0
Main-Class: TestCode
<invisible blank line here>

I've heard that a blank line is required in the .mf file so I've put one in there just in case. 我听说.mf文件中必须有一个空白行,因此我在其中放置了一个以防万一。

The project name is TestCode it is in the "default package" under TestCode.java 项目名称为TestCode,位于TestCode.java下的“默认包”中

EDIT 2: 编辑2:

I unpacked the .jar file and looked at its contents the manifest.mf file inside the .jar has the correct class path listed for the .class file which contains the main method. 我解压缩了.jar文件,并查看了其内容。.jar中的manifest.mf文件具有列出的.class文件的正确类路径,该文件包含main方法。 (most of these projects have only one .class file) and yet I still get the "Could not find the main class" error. (这些项目大多数都只有一个.class文件),但是我仍然收到“找不到主类”错误。

The main class is clearly inside the .jar file, the manifest properly points to it and it still won't run the program. 主类显然位于.jar文件中,清单正确地指向了它,但它仍然不会运行该程序。

main -class: Packagename.Classname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM