Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you build a JAR in eclipse with a custom manifest file?

I am trying to to build a Felix bundle in Eclipse. This basically includes having Eclipse create a JAR (through export) and adding my custom manifest file, however, I can't seem to get this to work. When I try exporting a JAR file, my custom manifest file shows up in the JAR, but doesn't ever get added to the right location within the JAR (meta-inf). This causes another default manifest file, which is created by Eclipse, to be added to my JAR file.

Note: I am using Eclipse's built in JAR export tool and selecting the option to use an existing manifest file from my workspace.

I'm sure there is some small detail being overlooked, but I am a little stumped.

Thanks for your help.

like image 250
Robert Greiner Avatar asked Jul 09 '09 21:07

Robert Greiner


2 Answers

See Java Course - Creating a Java Application with Eclipse for doing it from UI.

alt text

You could also run Ant's jar task from Eclipse.

<target name="jar" depends="compile">
  <mkdir dir="${jar.dest}" />
  <jar
    manifest="manifest.txt"
    jarfile="${build.jar}"
    basedir="${build.dest}">
  </jar>
</target>

Edit: For OSGi bundles, there's Bnd, the bundle tool by Peter Kriens. That'll generate manifest and build jar for you. The tool is capable as acting as command line tool as well as Ant, Maven, and Eclipse plugin.

like image 200
Eugene Yokota Avatar answered Nov 15 '22 06:11

Eugene Yokota


IF you use the Maven plugin (m2clipse), you can precise the manifest file in the maven configuration file of your project (pom.xml), in the "build section".

The manifest file will be added to the jar when you build it with maven (goal "mvn package").

like image 45
Benoit Courtine Avatar answered Nov 15 '22 07:11

Benoit Courtine