简体   繁体   中英

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 ?

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 (eg 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.

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>

当您使用jar cf jar-file inputs-files创建jar时,会创建一个默认清单jar cf jar-file inputs-files

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.

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

See Eclipse Documentation

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

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

Rightclick Project->Export->Select in Folder Java "Runnable Jar File"->
在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM