How can I create a Manifest
file for a group of JAR file I have already created.
I used Eclipse to create my JAR file.
Is there any better way o
A default manifest file is created when you create a jar
using jar cf jar-file inputs-files
.
A manifest is a simple text file, Sun's tutorial describes its contents in detail.
All you have to do is create such a file and update the JAR files with this command:
jar cfm <jar-file> <manifest-addition>
With Ant you can use jar task. It has a manifest option to specify all the attributes yo need to include. Something like this:
<target name="create-my-jar">
<jar jarfile="foo.jar" basedir="bin/classes">
<manifest>
<attribute name="Class-Path" value="xxx"/>
<attribute name="Ant-Version" value="${ant.version}"/>
<attribute name="Created-By" value="JDK ${java.version} (${java.vendor})"/>
<attribute name='Specification-Title' value='xxx' />
<attribute name='Specification-Version' value='xxx' />
<attribute name='Specification-Vendor' value='xxx' />
<attribute name='Implementation-Title' value='xxx' />
<attribute name='Implementation-Version' value='xxx' />
<attribute name='Implementation-Vendor' value='xxx' />
<attribute name='Implementation-Vendor-Id' value='xxx' />
<attribute name='Implementation-Vendor-URL' value='xxx' />
<attribute name="Built-By" value="${user.name}"/>
<attribute name='Build-Date' value='xxx'/>
<attribute name='Build-Time' value='xxx'/>
</manifest>
</jar>
</target>
Eclipse provides options to generate a manifest file for the Jar, save that generated manifest into the project, or use a specified file for the manifest.
I have Eclipse 3.4.2 and it's on the fourth screen in this process:
Right-click Project -> Export -> Java/JAR file, Next, JAR File Specification, Next, JAR Packaging Options, Next, JAR Manifest Specification.
The default is to just generate a default manifest for the JAR, and not to save the generated file back to the project, so if you open up your JAR file, it will have a manifest, but it will just have something like:
Manifest-Version: 1.0
in it.
If you want to change your existing JARs without re-building them, the easiest way is probably to just do as mad-j suggested and open them with a Zip tool and edit the existing /META-INF/MANIFEST.MF file and save it back into the JAR.
I just ran into this problem today.
Yes, Eclipse will create the Manifest for you, but it's really a joke.
It only includes the line Manifest-Version: 1.0
. I have not figured out how to make it add my Main class, so I created my own MANIFEST.MF file, added it to my project main directory (not src and not lib). Then, when I go to Export > JAR File, hit Next all the way to the end (do not hit Finish too early) and click the option to select manifest from project. Select the Manifest file you just added to your project. Make sure the Manifest has the path to your Main class (e.g. com.company etc). For example this is how a basic Manifest file would look like:
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: MyPackage.MyClass
I tried @Michael's method but I ended up with no class files left in my JAR and only Manifest files.. oh well. My above method works well.
Using Eclipse, on the JAR Manifest Specification page at the bottom, there is a text box where you can browse for your Main class. Browse to your Main class and click Finish. This generates the manifest WITH the main class information allowing the jar file to be executed. -Dev On