Automatically Creating Manifest File with Eclipse

2020-03-01 06:34发布

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?

8条回答
干净又极端
2楼-- · 2020-03-01 07:00

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

查看更多
放荡不羁爱自由
3楼-- · 2020-03-01 07:01

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>
查看更多
祖国的老花朵
4楼-- · 2020-03-01 07:03

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.

查看更多
Deceive 欺骗
5楼-- · 2020-03-01 07:04

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.

查看更多
在下西门庆
6楼-- · 2020-03-01 07:14

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

查看更多
霸刀☆藐视天下
7楼-- · 2020-03-01 07:23

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.

查看更多
登录 后发表回答