使用Eclipse为JAR文件自动创建清单文件

时间:2021-04-11 13:28:48

How can I create a Manifest file for a group of JAR file I have already created.

如何为已经创建的JAR文件组创建清单文件。

I used Eclipse to create my JAR file.

我使用Eclipse来创建JAR文件。

Is there any better way of creating a JAR file that has a Manifest?

有更好的方法来创建具有清单的JAR文件吗?

8 个解决方案

#1


6  

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.

Eclipse提供了为Jar生成清单文件、将生成的清单保存到项目中或为清单使用指定文件的选项。

I have Eclipse 3.4.2 and it's on the fourth screen in this process:

我有Eclipse 3.4.2,在这个过程的第四个屏幕上:

Right-click Project -> Export -> Java/JAR file, Next, JAR File Specification, Next, JAR Packaging Options, Next, JAR Manifest Specification.

右键单击项目->导出-> Java/JAR文件,Next, JAR文件规范,Next, JAR打包选项,Next, JAR清单规范。

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:

默认情况是为JAR生成一个默认的清单,而不是将生成的文件保存到项目中,所以如果打开JAR文件,它会有一个清单,但是它会有如下内容:

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.

如果您想要更改现有的jar,而不需要重新构建它们,最简单的方法可能就是按照madj -j的建议,用一个Zip工具打开它们,并编辑现有的/META-INF/MANIFEST。MF文件并将其保存到JAR中。

#2


5  

I just ran into this problem today.

我今天刚遇到这个问题。

Yes, Eclipse will create the Manifest for you, but it's really a joke.

是的,Eclipse将为您创建Manifest,但这确实是一个玩笑。

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:

它只包含行显式版本:1.0。我还没有弄清楚如何添加我的主类,所以我创建了自己的清单。MF文件,添加到我的项目主目录(不是src,也不是lib)。然后,当我去导出> JAR文件时,点击Next直到结束(不要过早地点击Finish),然后单击选项从项目中选择manifest。选择您刚刚添加到项目中的清单文件。确保舱单有通往你的主类(例如com.company等)的路径。例如,这就是基本清单文件的样子:

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.

我尝试了@Michael的方法,但是我的JAR中没有类文件,只有Manifest文件。哦。我上面的方法很有效。

#3


3  

A manifest is a simple text file, Sun's tutorial describes its contents in detail.

清单是一个简单的文本文件,Sun的教程详细描述了它的内容。

All you have to do is create such a file and update the JAR files with this command:

您所要做的就是创建这样一个文件并使用以下命令更新JAR文件:

jar cfm <jar-file> <manifest-addition>

#4


3  

With Ant you can use jar task. It has a manifest option to specify all the attributes yo need to include. Something like this:

使用Ant,您可以使用jar任务。它有一个manifest选项来指定您需要包含的所有属性。是这样的:

  <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>

#5


0  

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

当您使用jar cf jar文件输入文件创建jar时,将创建一个默认的清单文件。

#6


0  

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.

清单文件是文本文件。由于JAR文件实际上是ZIP文件,您还可以使用类似7-zip的工具添加清单。当然,这并不适用于签名jar。

#7


0  

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

您还可以看一下这个文档,这帮助我使用Eclipse向导解决了这个问题。

See Eclipse Documentation

看到Eclipse文档

#8


0  

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

使用Eclipse,在底部的JAR清单规范页面上,有一个文本框,您可以在其中浏览您的主类。浏览到主类并单击Finish。这将生成带有主类信息的清单,允许执行jar文件。- dev上

#1


6  

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.

Eclipse提供了为Jar生成清单文件、将生成的清单保存到项目中或为清单使用指定文件的选项。

I have Eclipse 3.4.2 and it's on the fourth screen in this process:

我有Eclipse 3.4.2,在这个过程的第四个屏幕上:

Right-click Project -> Export -> Java/JAR file, Next, JAR File Specification, Next, JAR Packaging Options, Next, JAR Manifest Specification.

右键单击项目->导出-> Java/JAR文件,Next, JAR文件规范,Next, JAR打包选项,Next, JAR清单规范。

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:

默认情况是为JAR生成一个默认的清单,而不是将生成的文件保存到项目中,所以如果打开JAR文件,它会有一个清单,但是它会有如下内容:

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.

如果您想要更改现有的jar,而不需要重新构建它们,最简单的方法可能就是按照madj -j的建议,用一个Zip工具打开它们,并编辑现有的/META-INF/MANIFEST。MF文件并将其保存到JAR中。

#2


5  

I just ran into this problem today.

我今天刚遇到这个问题。

Yes, Eclipse will create the Manifest for you, but it's really a joke.

是的,Eclipse将为您创建Manifest,但这确实是一个玩笑。

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:

它只包含行显式版本:1.0。我还没有弄清楚如何添加我的主类,所以我创建了自己的清单。MF文件,添加到我的项目主目录(不是src,也不是lib)。然后,当我去导出> JAR文件时,点击Next直到结束(不要过早地点击Finish),然后单击选项从项目中选择manifest。选择您刚刚添加到项目中的清单文件。确保舱单有通往你的主类(例如com.company等)的路径。例如,这就是基本清单文件的样子:

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.

我尝试了@Michael的方法,但是我的JAR中没有类文件,只有Manifest文件。哦。我上面的方法很有效。

#3


3  

A manifest is a simple text file, Sun's tutorial describes its contents in detail.

清单是一个简单的文本文件,Sun的教程详细描述了它的内容。

All you have to do is create such a file and update the JAR files with this command:

您所要做的就是创建这样一个文件并使用以下命令更新JAR文件:

jar cfm <jar-file> <manifest-addition>

#4


3  

With Ant you can use jar task. It has a manifest option to specify all the attributes yo need to include. Something like this:

使用Ant,您可以使用jar任务。它有一个manifest选项来指定您需要包含的所有属性。是这样的:

  <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>

#5


0  

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

当您使用jar cf jar文件输入文件创建jar时,将创建一个默认的清单文件。

#6


0  

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.

清单文件是文本文件。由于JAR文件实际上是ZIP文件,您还可以使用类似7-zip的工具添加清单。当然,这并不适用于签名jar。

#7


0  

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

您还可以看一下这个文档,这帮助我使用Eclipse向导解决了这个问题。

See Eclipse Documentation

看到Eclipse文档

#8


0  

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

使用Eclipse,在底部的JAR清单规范页面上,有一个文本框,您可以在其中浏览您的主类。浏览到主类并单击Finish。这将生成带有主类信息的清单,允许执行jar文件。- dev上