有趣的信息可能在这里:
http://wiki.netbeans.org/FaqNoMainClass
我有一个带有自定义清单文件的Java类库项目 - 非常适合OSGI包。要使这个工作首先编辑project.properties并设置:
manifest.file=manifest.mf manifest.available=true
在项目目录中创建自己的自定义manifest.mf文件。
(此时如果您尝试清理/构建,您仍然无法获得自定义清单文件 - NetBeans将提供自己的。这是因为build-impl.xml Ant目标“-do-jar-with-libraries-without -manifest“在”-do-jar-with-manifest“之后被立即调用,用默认的NetBeans清单JAR覆盖自定义清单JAR文件。)
将自定义目标添加到build.xml文件,如下所示:
<target name="-do-jar-with-libraries-without-manifest"> <!-- Inserted to prevent target from running so we can have a custom manifest file with a class library project type. --> </target>
在NetBeans 6.7.1中测试
请注意,您可以通过ant任务动态创建清单并动态设置属性。
首先,您必须更新“nbproject”目录中的Netbeans“project.properties”文件。将以下行添加到文件中:
manifest.file=manifest.mf
接下来,使用“build.xml”文件创建一个ant任务来创建/更新清单。在此示例中,我们将设置jar文件的版本号和日期。
<target name="-pre-init"> <property name="project.name" value="My Library" /> <property name="version.num" value="1.4.1" /> <tstamp> <format property="NOW" pattern="yyyy-MM-dd HH:mm:ss z" /> </tstamp> <!-- <exec outputproperty="svna.version" executable="svnversion"> <arg value="-c" /> <redirector> <outputfilterchain> <tokenfilter> <replaceregex pattern="^[0-9]*:?" replace="" flags="g"/> <replaceregex pattern="M" replace="" flags="g"/> </tokenfilter> </outputfilterchain> </redirector> </exec> --> <manifest file="MANIFEST.MF"> <attribute name="Bundle-Name" value="${project.name}" /> <attribute name="Bundle-Version" value="${version.num}" /> <attribute name="Bundle-Date" value="${NOW}" /> <!--<attribute name="Bundle-Revision" value="${svna.version}" />--> <attribute name="Implementation-Title" value="${project.name}" /> <attribute name="Implementation-Version" value="${version.num}" /> <attribute name="Implementation-URL" value="http://www.example.com" /> </manifest> </target>
这将在您的netbeans项目目录中创建一个清单文件,并将其填充到您的jar文件中。如果要从netbeans项目目录中删除自动生成的清单文件,只需创建另一个ant任务(当然是post jar):
<target name="-post-jar"> <delete file="MANIFEST.MF"/> </target>
你可以编辑 nbproject/build-impl.xml 添加如下所需的属性:
nbproject/build-impl.xml
.... <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass"> <manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update"> <attribute name="Main-Class" value="${main.class}"/> <attribute name="Property1" value="foo"/> <attribute name="Property2" value="bar"/> </manifest> </target> ....
这将导致a MANIFEST.MF 在这样的jar文件中:
MANIFEST.MF
Manifest-Version: 1.0 ... Property1: foo Property2: bar
在Netbeans 8.1上测试过。
为什么不使用对我来说效果很好的maven项目呢?例如。 阿帕奇费利克斯
看到 这个可插拔的Swing示例 我在netbeans中创建的。
看到 的 本文 强> 。
这里描述了如何
如果您使用maven(nbm-maven-plugin),请查看此内容
NBM Maven插件
在与build.xml相同的目录中 你可以把你的manifest.mf文件
我正在使用Netbeans 6.7.1 原来是build-imp.xml(Netbeans使用的实际构建脚本)
所以..确保你有项目属性,运行,主类填充 - 东西 -
我认为这是一些无证的功能:(
这是我的明确内容:
Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build Bundle-ManifestVersion: 2 Bundle-Name: jinstall Bundle-SymbolicName: jinstall Import-Package: ( .... ) Export-Package: ( .... ) Bundle-Activator: ( ..... )