I noticed that JAR, WAR and EAR files have a MANIFEST.MF
file under the META-INF
folder.
我注意到JAR,WAR和EAR文件在META-INF文件夹下有一个MANIFEST.MF文件。
What is the use of the MANIFEST.MF
file? What all things can be specified in this file?
MANIFEST.MF文件的用途是什么?可以在此文件中指定所有内容?
2 个解决方案
#1
73
The content of the Manifest file in a JAR file created with version 1.0 of the Java Development Kit is the following.
使用Java Development Kit 1.0版创建的JAR文件中的Manifest文件的内容如下。
Manifest-Version: 1.0
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
所有条目都是名称 - 值对。标题的名称通过冒号与其值分隔。默认清单显示它符合清单规范的1.0版。清单还可以包含有关存档中打包的其他文件的信息。清单中记录的文件信息究竟取决于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文件,则MANIFEST.MF文件没有用处。 JAR文件的大多数用法不仅仅是简单的归档和压缩,还需要在清单文件中包含特殊信息。以下总结了一些特殊用途JAR文件功能所需的标头的简要说明
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:
捆绑为JAR文件的应用程序:如果应用程序捆绑在JAR文件中,则需要告知Java虚拟机应用程序的入口点是什么。入口点是具有public static void main(String [] args)方法的任何类。此信息在Main-Class标头中提供,该标头具有以下一般形式:
Main-Class: classname
The value classname is to be replaced with the application's entry point.
值classname将替换为应用程序的入口点。
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:
下载扩展:下载扩展是由其他JAR文件的清单文件引用的JAR文件。在典型情况下,applet将捆绑在JAR文件中,该文件的清单引用JAR文件(或多个JAR文件),这些文件将作为该applet用途的扩展。扩展可以以相同的方式相互引用。下载扩展名在applet,应用程序或其他扩展的清单文件的Class-Path头字段中指定。 Class-Path标头可能如下所示,例如:
Class-Path: servlet.jar infobus.jar acme/beans.jar
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.
使用此标头,文件servlet.jar,infobus.jar和acme / beans.jar中的类将用作applet或应用程序的扩展。 Class-Path标头中的URL是相对于applet或应用程序的JAR文件的URL给出的。
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:
包密封:可以选择密封JAR文件中的包,这意味着该包中定义的所有类必须存档在同一个JAR文件中。可以密封包以确保软件中的类之间的版本一致性或作为安全措施。要封装包,需要为包添加一个Name头,后跟一个Sealed头,类似于:
Name: myCompany/myPackage/
Sealed: true
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标头的值是包的相对路径名。请注意,它以'/'结尾,以区别于文件名。 Name头后面的任何标头,没有任何插入的空行,适用于Name头中指定的文件或包。在上面的示例中,因为Sealed标头出现在Name:myCompany / myPackage标头之后,之间没有空行,所以Sealed标头将被解释为仅应用于包myCompany / myPackage。
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标题下方。此示例显示所有版本控制标头:
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."
#2
15
Manifest.MF contains information about the files contained in the JAR file.
Manifest.MF包含有关JAR文件中包含的文件的信息。
Whenever a JAR file is created a default manifest.mf file is created inside META-INF folder and it contains the default entries like this:
每当创建一个JAR文件时,都会在META-INF文件夹中创建一个默认的manifest.mf文件,它包含如下默认条目:
Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
These are entries as “header:value” pairs. The first one specifies the manifest version and second one specifies the JDK version with which the JAR file is created.
这些条目为“header:value”对。第一个指定清单版本,第二个指定用于创建JAR文件的JDK版本。
Main-Class header: When a JAR file is used to bundle an application in a package, we need to specify the class serving an entry point of the application. We provide this information using ‘Main-Class’ header of the manifest file,
Main-Class标头:当使用JAR文件捆绑包中的应用程序时,我们需要指定服务于应用程序入口点的类。我们使用清单文件的“Main-Class”标题提供此信息,
Main-Class: {fully qualified classname}
主类:{完全合格的类名}
The ‘Main-Class’ value here is the class having main method. After specifying this entry we can execute the JAR file to run the application.
这里的'Main-Class'值是具有main方法的类。指定此条目后,我们可以执行JAR文件来运行应用程序。
Class-Path header: Most of the times we need to access the other JAR files from the classes packaged inside application’s JAR file. This can be done by providing their fully qualified paths in the manifest file using ‘Class-Path’ header,
Class-Path标头:我们大多数时候需要从应用程序的JAR文件中打包的类中访问其他JAR文件。这可以通过使用“Class-Path”标头在清单文件中提供完全限定的路径来完成,
Class-Path: {jar1-name jar2-name directory-name/jar3-name}
Class-Path:{jar1-name jar2-name directory-name / jar3-name}
This header can be used to specify the external JAR files on the same local network and not inside the current JAR.
此标头可用于在同一本地网络上指定外部JAR文件,而不是在当前JAR中指定。
Package version related headers: When the JAR file is used for package versioning the following headers are used as specified by the Java language specification:
与包版本相关的标头:当JAR文件用于包版本控制时,将按照Java语言规范的指定使用以下标头:
Headers in a manifest
Header | Definition
-------------------------------------------------------------------
Name | The name of the specification.
Specification-Title | The title of the specification.
Specification-Version | The version of the specification.
Specification-Vendor | The vendor of the specification.
Implementation-Title | The title of the implementation.
Implementation-Version | The build number of the implementation.
Implementation-Vendor | The vendor of the implementation.
Package sealing related headers:
包装密封相关标头:
We can also specify if any particular packages inside a JAR file should be sealed meaning all the classes defined in that package must be archived in the same JAR file. This can be specified with the help of ‘Sealed’ header,
我们还可以指定JAR文件中的任何特定包是否应该被密封,这意味着该包中定义的所有类必须存档在同一个JAR文件中。这可以在'密封'标题的帮助下指定,
Name: {package/some-package/} Sealed:true
名称:{package / some-package /}密封:真
Here, the package name must end with ‘/’.
此处,包名称必须以“/”结尾。
Enhancing security with manifest files:
使用清单文件增强安全性:
We can use manifest files entries to ensure the security of the web application or applet it packages with the different attributes as ‘Permissions’, ‘Codebae’, ‘Application-Name’, ‘Trusted-Only’ and many more.
我们可以使用清单文件条目来确保包含的Web应用程序或applet的安全性具有“权限”,“Codebae”,“应用程序名称”,“仅受信任”等不同属性。
META-INF folder:
META-INF文件夹:
This folder is where the manifest file resides. Also, it can contain more files containing meta data about the application. For example, in an EJB module JAR file, this folder contains the EJB deployment descriptor for the EJB module along with the manifest file for the JAR. Also, it contains the xml file containing mapping of an abstract EJB references to concrete container resources of the application server on which it will be run.
此文件夹是清单文件所在的位置。此外,它可以包含更多包含有关应用程序的元数据的文件。例如,在EJB模块JAR文件中,此文件夹包含EJB模块的EJB部署描述符以及JAR的清单文件。此外,它还包含xml文件,其中包含抽象EJB引用的映射,以及将在其上运行的应用程序服务器的具体容器资源。
Reference:
https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
参考:https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
#1
73
The content of the Manifest file in a JAR file created with version 1.0 of the Java Development Kit is the following.
使用Java Development Kit 1.0版创建的JAR文件中的Manifest文件的内容如下。
Manifest-Version: 1.0
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
所有条目都是名称 - 值对。标题的名称通过冒号与其值分隔。默认清单显示它符合清单规范的1.0版。清单还可以包含有关存档中打包的其他文件的信息。清单中记录的文件信息究竟取决于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文件,则MANIFEST.MF文件没有用处。 JAR文件的大多数用法不仅仅是简单的归档和压缩,还需要在清单文件中包含特殊信息。以下总结了一些特殊用途JAR文件功能所需的标头的简要说明
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:
捆绑为JAR文件的应用程序:如果应用程序捆绑在JAR文件中,则需要告知Java虚拟机应用程序的入口点是什么。入口点是具有public static void main(String [] args)方法的任何类。此信息在Main-Class标头中提供,该标头具有以下一般形式:
Main-Class: classname
The value classname is to be replaced with the application's entry point.
值classname将替换为应用程序的入口点。
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:
下载扩展:下载扩展是由其他JAR文件的清单文件引用的JAR文件。在典型情况下,applet将捆绑在JAR文件中,该文件的清单引用JAR文件(或多个JAR文件),这些文件将作为该applet用途的扩展。扩展可以以相同的方式相互引用。下载扩展名在applet,应用程序或其他扩展的清单文件的Class-Path头字段中指定。 Class-Path标头可能如下所示,例如:
Class-Path: servlet.jar infobus.jar acme/beans.jar
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.
使用此标头,文件servlet.jar,infobus.jar和acme / beans.jar中的类将用作applet或应用程序的扩展。 Class-Path标头中的URL是相对于applet或应用程序的JAR文件的URL给出的。
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:
包密封:可以选择密封JAR文件中的包,这意味着该包中定义的所有类必须存档在同一个JAR文件中。可以密封包以确保软件中的类之间的版本一致性或作为安全措施。要封装包,需要为包添加一个Name头,后跟一个Sealed头,类似于:
Name: myCompany/myPackage/
Sealed: true
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标头的值是包的相对路径名。请注意,它以'/'结尾,以区别于文件名。 Name头后面的任何标头,没有任何插入的空行,适用于Name头中指定的文件或包。在上面的示例中,因为Sealed标头出现在Name:myCompany / myPackage标头之后,之间没有空行,所以Sealed标头将被解释为仅应用于包myCompany / myPackage。
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标题下方。此示例显示所有版本控制标头:
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."
#2
15
Manifest.MF contains information about the files contained in the JAR file.
Manifest.MF包含有关JAR文件中包含的文件的信息。
Whenever a JAR file is created a default manifest.mf file is created inside META-INF folder and it contains the default entries like this:
每当创建一个JAR文件时,都会在META-INF文件夹中创建一个默认的manifest.mf文件,它包含如下默认条目:
Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
These are entries as “header:value” pairs. The first one specifies the manifest version and second one specifies the JDK version with which the JAR file is created.
这些条目为“header:value”对。第一个指定清单版本,第二个指定用于创建JAR文件的JDK版本。
Main-Class header: When a JAR file is used to bundle an application in a package, we need to specify the class serving an entry point of the application. We provide this information using ‘Main-Class’ header of the manifest file,
Main-Class标头:当使用JAR文件捆绑包中的应用程序时,我们需要指定服务于应用程序入口点的类。我们使用清单文件的“Main-Class”标题提供此信息,
Main-Class: {fully qualified classname}
主类:{完全合格的类名}
The ‘Main-Class’ value here is the class having main method. After specifying this entry we can execute the JAR file to run the application.
这里的'Main-Class'值是具有main方法的类。指定此条目后,我们可以执行JAR文件来运行应用程序。
Class-Path header: Most of the times we need to access the other JAR files from the classes packaged inside application’s JAR file. This can be done by providing their fully qualified paths in the manifest file using ‘Class-Path’ header,
Class-Path标头:我们大多数时候需要从应用程序的JAR文件中打包的类中访问其他JAR文件。这可以通过使用“Class-Path”标头在清单文件中提供完全限定的路径来完成,
Class-Path: {jar1-name jar2-name directory-name/jar3-name}
Class-Path:{jar1-name jar2-name directory-name / jar3-name}
This header can be used to specify the external JAR files on the same local network and not inside the current JAR.
此标头可用于在同一本地网络上指定外部JAR文件,而不是在当前JAR中指定。
Package version related headers: When the JAR file is used for package versioning the following headers are used as specified by the Java language specification:
与包版本相关的标头:当JAR文件用于包版本控制时,将按照Java语言规范的指定使用以下标头:
Headers in a manifest
Header | Definition
-------------------------------------------------------------------
Name | The name of the specification.
Specification-Title | The title of the specification.
Specification-Version | The version of the specification.
Specification-Vendor | The vendor of the specification.
Implementation-Title | The title of the implementation.
Implementation-Version | The build number of the implementation.
Implementation-Vendor | The vendor of the implementation.
Package sealing related headers:
包装密封相关标头:
We can also specify if any particular packages inside a JAR file should be sealed meaning all the classes defined in that package must be archived in the same JAR file. This can be specified with the help of ‘Sealed’ header,
我们还可以指定JAR文件中的任何特定包是否应该被密封,这意味着该包中定义的所有类必须存档在同一个JAR文件中。这可以在'密封'标题的帮助下指定,
Name: {package/some-package/} Sealed:true
名称:{package / some-package /}密封:真
Here, the package name must end with ‘/’.
此处,包名称必须以“/”结尾。
Enhancing security with manifest files:
使用清单文件增强安全性:
We can use manifest files entries to ensure the security of the web application or applet it packages with the different attributes as ‘Permissions’, ‘Codebae’, ‘Application-Name’, ‘Trusted-Only’ and many more.
我们可以使用清单文件条目来确保包含的Web应用程序或applet的安全性具有“权限”,“Codebae”,“应用程序名称”,“仅受信任”等不同属性。
META-INF folder:
META-INF文件夹:
This folder is where the manifest file resides. Also, it can contain more files containing meta data about the application. For example, in an EJB module JAR file, this folder contains the EJB deployment descriptor for the EJB module along with the manifest file for the JAR. Also, it contains the xml file containing mapping of an abstract EJB references to concrete container resources of the application server on which it will be run.
此文件夹是清单文件所在的位置。此外,它可以包含更多包含有关应用程序的元数据的文件。例如,在EJB模块JAR文件中,此文件夹包含EJB模块的EJB部署描述符以及JAR的清单文件。此外,它还包含xml文件,其中包含抽象EJB引用的映射,以及将在其上运行的应用程序服务器的具体容器资源。
Reference:
https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
参考:https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html