How do you build a JAR in eclipse with a custom manifest file?
Solution 1
See Java Course - Creating a Java Application with Eclipse for doing it from UI.
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.
Solution 2
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").
Robert Greiner
I'm a technical consultant living and working in Dallas, Texas. Blog Twitter: @wannagrabcoffee Github: robertgreiner Linkedin: Connect
Updated on July 19, 2022Comments
-
Robert Greiner almost 2 years
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.
-
Robert Greiner almost 15 yearsthat worked, thank you. I was selecting some of the wrong options within Eclipse.
-
gsgx about 11 yearsYour first link is broken.
-
Eugene Yokota about 11 years@gsingh2011 Java Course - Creating a Java Application with Eclipse works for me.
-
gsgx about 11 yearsMust have been my internet or something. Works for me too now, thanks.
-
Dioxin about 9 yearsFirst link is broken once again.