Netbeans manifest

不问归期 提交于 2019-11-30 01:45:02

Note that you can create a manifest on-the-fly via an ant task and set properties dynamically.

First, you must update your Netbeans "project.properties" file found in the "nbproject" directory. Add the following line to the file:

manifest.file=manifest.mf

Next, create an ant task to create/update the manifest using the "build.xml" file. In this example, we will set the version number and date of the jar file.

<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>

This will create a manifest file in your netbeans project directory and stuff it into your jar file. If you want to delete the autogenerated manifest file from your netbeans project directory, simply create another ant task (post jar of course):

<target name="-post-jar">
  <delete file="MANIFEST.MF"/>
</target> 

Interesting information might be here:

http://wiki.netbeans.org/FaqNoMainClass

I have a Java Class Library project with a custom manifest file - perfect for an OSGI bundle. To get this working first edit project.properties and set:

manifest.file=manifest.mf
manifest.available=true

Create your own custom manifest.mf file in the project directory.

(At this point if you try a clean/build you still won't get your custom manifest file - NetBeans will provide its own. This is because the build-impl.xml Ant target "-do-jar-with-libraries-without-manifest" is being called immediately after "-do-jar-with-manifest", overwriting your custom manifest JAR file with a default NetBeans manifest JAR.)

Add a custom target to your build.xml file as follows:

<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>

Tested in NetBeans 6.7.1

in the same dir as the build.xml you can put your manifest.mf file

I'm using Netbeans 6.7.1 Turns out that the build-imp.xml (the actual build script Netbeans uses)

  • doesn't have a target which runs if 'with manifest, without main-class'
  • but it does have one like 'with manifest, with main-class'

So.. make sure you have the project-properties,run,main-Class filled with -anything-

i think that's some undocumented feature :(

this is my manifest content:

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: ( ..... )

In case you using maven (nbm-maven-plugin), look at this

NBM Maven plugin

Why not using the a maven project, which worked well for me? E.g. apache felix

See this pluggable Swing example which I created in netbeans.

You can edit the nbproject/build-impl.xml adding the necessary properties like this:

....
<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>
....

This will result in a MANIFEST.MF in jar file like this:

Manifest-Version: 1.0
...
Property1: foo
Property2: bar

Tested on Netbeans 8.1.

See this article.

Here it is described how to

  • create own ant targets
  • add manual entries to manifest.mf for the output JAR
  • run custom ant targets from Netbeans
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!