ajib
ajib

Reputation:

Automatically Creating Manifest File with Eclipse for JAR Files

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 of creating a JAR file that has a Manifest?

Upvotes: 18

Views: 93492

Answers (10)

Deep Ghosh
Deep Ghosh

Reputation: 1

This is the solution. In the JAR MANIFEST Specification Tab use Generate the Manifest File and use Browse and select a file. (You can just use the one generated in your older ZIP). Then generate Jar file. Afterwards, Edit it to put any value.

Upvotes: 0

NoErrorNoCry
NoErrorNoCry

Reputation: 75

A little bit late but thats the most simple/efficient solution:

Rightclick Project->Export->Select in Folder Java "Runnable Jar File"->
enter image description here

Next-> Launch Configuration: Select that one you recently used to test your project, leave the rest as default

The manifest has now the relating entry to start the *.jar correct

Upvotes: 1

Kenneth V
Kenneth V

Reputation: 11

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

Upvotes: 0

Reedyseth
Reedyseth

Reputation: 41

Also you can take a look at this documentation, this helped me to solve the issue using the Eclipse wizard.

See Eclipse Documentation

Upvotes: 1

user195488
user195488

Reputation:

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.

Upvotes: 7

JuanZe
JuanZe

Reputation: 8167

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>

Upvotes: 3

Nate
Nate

Reputation: 16898

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.

Upvotes: 10

Joonas Pulakka
Joonas Pulakka

Reputation: 36577

Manifest files are text files. And since JAR files are actually ZIP files, you can also add the manifest using a tool like 7-zip. This doesn't work for signed JARs, of course.

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346506

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>

Upvotes: 3

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91349

A default manifest file is created when you create a jar using jar cf jar-file inputs-files.

Upvotes: 0

Related Questions