在Java中使用MANIFEST.MF文件 [英] Use of the MANIFEST.MF file in Java

查看:440
本文介绍了在Java中使用MANIFEST.MF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到JAR,WAR和EAR文件在 META-INF 文件夹下有一个 MANIFEST.MF 文件。

I noticed that JAR, WAR and EAR files have a MANIFEST.MF file under the META-INF folder.

MANIFEST.MF 文件的用途是什么?可以在此文件中指定所有内容吗?

What is the use of the MANIFEST.MF file? What all things can be specified in this file?

推荐答案

使用1.0版创建的JAR文件中的清单文件的内容Java Development Kit如下所示。

The content of the Manifest file in a JAR file created with version 1.0 of the Java Development Kit is the following.

Manifest-Version: 1.0

所有条目都是名称 - 值对。标题的名称通过冒号与其值分隔。默认清单显示它符合清单规范的1.0版。
清单还可以包含有关存档中打包的其他文件的信息。清单中记录的文件信息究竟取决于JAR文件的预期用途。默认清单文件不会假设它应记录哪些关于其他文件的信息,因此其单行仅包含有关其自身的数据。
特殊用途清单标题

All the entries are as name-value pairs. The name of a header is separated from its value by a colon. The default manifest shows that it conforms to version 1.0 of the manifest specification. The manifest can also contain information about the other files that are packaged in the archive. Exactly what file information is recorded in the manifest will depend on the intended use for the JAR file. The default manifest file makes no assumptions about what information it should record about other files, so its single line contains data only about itself. Special-Purpose Manifest Headers

根据JAR文件的预期角色,可能必须修改默认清单。如果仅为了存档而创建JAR文件,则MANIFEST.MF文件没有用处。
JAR文件的大多数用法不仅仅是简单的归档和压缩,还需要特殊信息才能在清单文件中。下面总结了一些特殊用途JAR文件函数所需的标题的简要说明

Depending on the intended role of the JAR file, the default manifest may have to be modified. If the JAR file is created only for the purpose of archival, then the MANIFEST.MF file is of no purpose. Most uses of JAR files go beyond simple archiving and compression and require special information to be in the manifest file. Summarized below are brief descriptions of the headers that are required for some special-purpose JAR-file functions

捆绑为JAR文件的应用程序:如果是应用程序捆绑在一个JAR文件中,需要告诉Java虚拟机应用程序的入口点是什么。入口点是具有public static void main(String [] args)方法的任何类。此信息在Main-Class标题中提供,该标题具有以下一般形式:

Applications Bundled as JAR Files: If an application is bundled in a JAR file, the Java Virtual Machine needs to be told what the entry point to the application is. An entry point is any class with a public static void main(String[] args) method. This information is provided in the Main-Class header, which has the general form:

Main-Class: classname

值类名将替换为应用程序的入口点。

The value classname is to be replaced with the application's entry point.

下载扩展程序:下载扩展程序是其他JAR文件的清单文件引用的JAR文件。在典型情况下,applet将捆绑在JAR文件中,该文件的清单引用JAR文件(或多个JAR文件),这些文件将作为该applet用途的扩展。扩展可以以相同的方式相互引用。
下载扩展名在applet,应用程序或其他扩展程序的清单文件的Class-Path头字段中指定。 Class-Path标头可能如下所示:例如:

Download Extensions: Download extensions are JAR files that are referenced by the manifest files of other JAR files. In a typical situation, an applet will be bundled in a JAR file whose manifest references a JAR file (or several JAR files) that will serve as an extension for the purposes of that applet. Extensions may reference each other in the same way. Download extensions are specified in the Class-Path header field in the manifest file of an applet, application, or another extension. A Class-Path header might look like this, for example:

Class-Path: servlet.jar infobus.jar acme/beans.jar

使用此标头,文件servlet.jar,infobus.jar和acme中的类/beans.jar将作为applet或应用程序的扩展。 Class-Path标头中的URL是相对于applet或应用程序的JAR文件的URL给出的。

With this header, the classes in the files servlet.jar, infobus.jar, and acme/beans.jar will serve as extensions for purposes of the applet or application. The URLs in the Class-Path header are given relative to the URL of the JAR file of the applet or application.

包装密封: A可以选择密封JAR文件中的包,这意味着该包中定义的所有类必须存档在同一个JAR文件中。可以密封包以确保软件中的类之间的版本一致性或作为安全措施。
要封装包,需要为包添加一个Name头,后跟一个Sealed头,类似于:

Package Sealing: A package within a JAR file can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. A package might be sealed to ensure version consistency among the classes in your software or as a security measure. To seal a package, a Name header needs to be added for the package, followed by a Sealed header, similar to this:

Name: myCompany/myPackage/
Sealed: true

名称标题的值是包的相对路径名。请注意,它以'/'结尾,以区别于文件名。 Name头后面的任何标头,没有任何插入的空行,适用于Name头中指定的文件或包。在上面的示例中,因为Sealed标头出现在Name:myCompany / myPackage标头之后,之间没有空行,所以Sealed标头将被解释为仅应用于包myCompany / myPackage。

The Name header's value is the package's relative pathname. Note that it ends with a '/' to distinguish it from a filename. Any headers following a Name header, without any intervening blank lines, apply to the file or package specified in the Name header. In the above example, because the Sealed header occurs after the Name: myCompany/myPackage header, with no blank lines between, the Sealed header will be interpreted as applying (only) to the package myCompany/myPackage.

包版本控制:包版本控制规范定义了几个用于保存版本信息的清单头。可以为每个包分配一组这样的头。版本控制标题应直接显示在包的Name标题下方。此示例显示了所有版本控制标头:

Package Versioning: The Package Versioning specification defines several manifest headers to hold versioning information. One set of such headers can be assigned to each package. The versioning headers should appear directly beneath the Name header for the package. This example shows all the versioning headers:

Name: java/util/
Specification-Title: "Java Utility Classes" 
Specification-Version: "1.2"
Specification-Vendor: "Sun Microsystems, Inc.".
Implementation-Title: "java.util" 
Implementation-Version: "build57"
Implementation-Vendor: "Sun Microsystems, Inc."

这篇关于在Java中使用MANIFEST.MF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆