Netbeans manifest
Asked Answered
K

8

24

Is it possible to add entries to the manifest.mf file of jars generated by netbeans?

to build an osgi bundle for instance.

Knoll answered 6/8, 2009 at 5:15 Comment(0)
M
23

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> 
Marola answered 4/12, 2011 at 12:53 Comment(3)
This works really well, thanks! But why don’t the Codebase and Permissions change ( it is stil set to default). Can this not be changed here?Kepi
-pre-init is run before project.properties is read, therefore manifest.file is unset while making the first target. However, the manifest file should be created before -do-init, otherwise manifest.available won't be set.Gelman
Thanks, that helped. I have also found a more detailed version of that answer here: javaxt.com/Tutorials/Netbeans/…Conlin
Z
6

Interesting information might be here:

http://wiki.netbeans.org/FaqNoMainClass

Zeist answered 22/10, 2009 at 14:49 Comment(2)
This is the correct answer! Simply create the desired manifest.mf in the project root and append "manifest.file=manifest.mf" to file project.properties. Assuming your project isn't setting any values in the manifest dynamically, that is. If you need to get fancy here, it's time to turn to maven!Rimbaud
Yepp. This is probably the best solution. Though optimally I would like there to be better gui options for modifying what ends up in the manifest file. But for now, this will do.Forenoon
O
2

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

Outthink answered 26/9, 2010 at 6:38 Comment(0)
W
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: ( ..... )
Was answered 12/8, 2009 at 15:6 Comment(2)
Yes, but the problem with that is that netbeans refuses any property it doesn't understand, and it doesn't understand much. All the osgi properties such as Bundle-ManifestVersion or Bundle-Activator are rejected.Knoll
I don't have that problem in ordinary netbeans 6.7.1 java-project. I can fill in any Bundle-xxxx property in the custom manifest. What happened in my case was that it completely ignored the whole manifest file and created a default manifest.Was
G
1

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

NBM Maven plugin

Gyatt answered 18/11, 2013 at 12:55 Comment(1)
Link is no longer accessible.Oslo
A
0

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.

Azoth answered 7/11, 2009 at 12:17 Comment(0)
A
0

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.

Arteriotomy answered 9/10, 2018 at 20:39 Comment(0)
T
-2

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
Twibill answered 29/9, 2009 at 10:8 Comment(2)
The referenced article doesn't speak very directly to this question. If you're referring to the custom ant task ... that's not a very good approach to the simple task of adding an entry to the manifest, IMHO.Rimbaud
There is no article on the link anymore.Arteriotomy

© 2022 - 2024 — McMap. All rights reserved.