在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文件?
Am I missing something? Is there a way (other than manually altering the manifest file) to produce executable jar files?
编辑:是的,我尝试清理并重建它在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 Application项目相同的问题。修改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>
另一种方法是在NetBeans中构建一个不使用Maven的Java Application项目。选择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屋!