Java – How to build a JAR in eclipse with a custom manifest file

apache-felixeclipsejarjavamanifest

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.

Best Solution

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.