文档

Java™教程
隐藏目录
设置包版本信息
教程: 部署
课程: 在JAR文件中打包程序
章节: 使用清单文件: 基础知识

设置包版本信息

在JAR文件的清单中,您可能需要包含包版本信息。您可以通过清单中的以下标头提供此信息:

清单中的标头
标头 定义
Name 规范的名称。
Specification-Title 规范的标题。
Specification-Version 规范的版本。
Specification-Vendor 规范的供应商。
Implementation-Title 实现的标题。
Implementation-Version 实现的构建号。
Implementation-Vendor 实现的供应商。

每个包可以分配一组此类标头。版本标头应出现在包的Name标头之下。以下示例显示了所有版本标头:

Name: java/util/
Specification-Title: Java Utility Classes
Specification-Version: 1.2
Specification-Vendor: Example Tech, Inc.
Implementation-Title: java.util
Implementation-Version: build57
Implementation-Vendor: Example Tech, Inc.

有关包版本标头的更多信息,请参阅Package Versioning specification

示例

我们希望在MyJar.jar的清单中包含上述示例中的标头。

我们首先创建一个名为Manifest.txt的文本文件,内容如下:

Name: java/util/
Specification-Title: Java Utility Classes
Specification-Version: 1.2
Specification-Vendor: Example Tech, Inc.
Implementation-Title: java.util 
Implementation-Version: build57
Implementation-Vendor: Example Tech, Inc.

警告: 文本文件必须以新行或回车符结束。如果最后一行没有以新行或回车符结束,它将无法正确解析。

然后,我们通过输入以下命令来创建名为MyJar.jar的JAR文件:

jar cfm MyJar.jar Manifest.txt MyPackage/*.class

这将创建带有以下内容的具有清单的JAR文件:

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
Name: java/util/
Specification-Title: Java Utility Classes
Specification-Version: 1.2
Specification-Vendor: Example Tech, Inc.
Implementation-Title: java.util 
Implementation-Version: build57
Implementation-Vendor: Example Tech, Inc.

上一页:将类添加到JAR文件的类路径
下一页:在JAR文件中封装包