在 NetBeans 中生成可执行 jar [英] Producing executable jar in NetBeans
问题描述
我使用的是 NetBeans 6.5,出于某种原因,它不会开箱即用"生成可执行的 jar.
I'm using NetBeans 6.5 and for some reason it won't produce executable jar "out of the box".
我将我的项目设置为主项目,在项目属性运行"菜单中定义了主类,当我按 F6 运行它时,它完美无缺.
I set my project to be the main project, defined main class in the project properties "run" menu and it works flawlessly when I press F6 to run it.
我查看了清单文件,它确实没有在那里定义主类,也省略了库依赖项.
I looked at the manifest file and it indeed didn't define the main class there, and also omitted the library dependencies.
我错过了什么吗?有没有办法(除了手动更改清单文件)来生成可执行的 jar 文件?
是的,我尝试过清理和重建,它在 dist 文件夹中生成了 jar,仍然具有相同的 manifest.mf
yes, I tried clean and rebuild and it produced the jar in the dist folder, still with the same manifest.mf
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b23 (Sun Microsystems Inc.)
推荐答案
我刚刚在 NetBeans 7.2.1 的 Maven Java 应用程序项目中遇到了同样的问题.修改 pom.xml 文件以包含 Maven 程序集插件,对 myrho 的答案进行了一次调整(需要引用预定义的描述符jar-with-dependencies"):
I just had the same problem in NetBeans 7.2.1 with a Maven Java Application project. Modify the pom.xml file to include the maven assembly plugin with one tweak to myrho's answer (needs to reference the predefined descriptor "jar-with-dependencies"):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.app.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
另一种方法是在不使用 Maven 的 NetBeans 中构建 Java 应用程序项目.选择 File -> Project Properties -> Build -> Packaging 并选中Copy Dependent Libraries"复选框.
An alternate method is to build a Java Application project in NetBeans that doesn't use Maven. Select File -> Project Properties -> Build -> Packaging and check the "Copy Dependent Libraries" checkbox.
这篇关于在 NetBeans 中生成可执行 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!