JAR清单文件-规范与实现之间的区别 [英] JAR Manifest file - Difference between Specification and Implementation

查看:152
本文介绍了JAR清单文件-规范与实现之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将版本信息(以及可能有关该jar的其他一些元数据)添加到我创建的库的jar中.但是,我不确定要使用什么属性.我发现规范以及文档解释说可以有一个Specification-Version和一个(以及两者的标题和供应商).但是,两者都没有正确解释规范和实现之间的区别.

I want to add versioning information (and possibly some other metadata about the jar) to a jar of a library I created. However, I am not sure what attribute to use. I found that the specification as well the documentation explain that there can be a Specification-Version and an Implementation-Version (and a title and vendor for both). But neither properly explains what the difference between Specification and Implementation is.

我也看了不同的例子.

I also looked at different examples.

  • 文档中的一个使用易读的名称表示规范标题",而包名称表示实现标题".点号分隔的版本号用于规范版本,而简单的内部版本号用于实现版本.
  • gradle教程似乎只使用了一个Implementation-Version和一个人类可读的字符串作为Implementation-Title
  • 另一个问题我找到了一个示例,其中有针对不同软件包的多个实现版本.
  • The one from the documentation uses a human readable name for the Specification-Title and a package name for the Implementation-Title. A dot-separated version number is used for the Specification-Version while a simple build number is used for the Implementation-Version.
  • The gradle tutorial seems to just use an Implementation-Version and a human-readable string for the Implementation-Title
  • In another question I found an example in which there were several Implementation-Versions for different packages.

这里的规范和实现元数据之间到底有什么区别?应该如何使用这些不同的属性(尤其是版本号)?规范的供应商和实现方式有何不同?

What exactly is the difference between the Specification and Implementation Metadata here? How should these different attributes (especially the version numbers) be used? How does it make sense that the vendor of the specification and the implementation are different?

它甚至发挥了我在其中发挥的作用吗?

Does it even play a role what I put in there?

推荐答案

规范-版本必须由ASCII数字序列组成,并用ASCII句点分隔.不允许使用其他字符,不能在值的开头或结尾使用句点,也不允许连续的句点.

The Specification-Version must consist of sequences of ASCII digits, separated by ASCII periods. No other characters are allowed, periods cannot be at the start or end of the value, and consecutive periods are not allowed.

实施-版本是自由格式的字符串.它可以具有任何格式.

The Implementation-Version is a free-form string. It can have any format.

Specification-Version始终与包关联.如果您为整个清单而不是特定的软件包指定它,则它将应用于.jar文件中的所有软件包.

Specification-Version is always associated with a package. If you specify it for the entire manifest instead of for a specific package, it applies to all packages in the .jar file.

Specification-Version被许多Java技术用来解决依赖关系.如果某些程序说需要2.1版或更高版本的JMF库,则某些Java环境将分析每个清单的Specification-Version中具有匹配的Specification-Title的数字,并确保使用正确的版本(和没有其他版本)在运行时在类路径中可用.

The Specification-Version is used by a number of Java technologies as a means of resolving dependencies. If some program says it needs, say, version 2.1 or later of the JMF library, some Java environments will analyze the numbers in the Specification-Version of each manifest with a matching Specification-Title, and will make sure that the correct version (and no other version) is available in the classpath at runtime.

实际上, Package.isCompatibleWith 方法可以非常方便地进行检查.您甚至可以使用它来检查Java的最低版本:

In fact, the Package.isCompatibleWith method does that very check. You can even use it to check for a minimum Java version:

if (System.class.getPackage().isCompatibleWith("1.6")) {
    System.out.println("Running in Java 1.6 or later.");
}

更新

以上内容在Java 9模块化应用程序中不起作用.从 java.lang.Package文档:

为命名模块中的类自动定义的包具有以下属性:

•规范和实现的标题,版本和供应商未指定.

A Package automatically defined for classes in a named module has the following properties:

• The specification and implementation titles, versions, and vendors are unspecified.

为未命名模块中的类自动定义的包具有以下属性:

•规范和实现的标题,版本和供应商未指定.

A Package automatically defined for classes in an unnamed module has the following properties:

• The specification and implementation titles, versions, and vendors are unspecified.

作为模块运行的Java 9程序应使用 ModuleDescriptor.version()代替.请注意, ModuleDescriptor.Version类是可比的:

Java 9 programs running as modules should use ModuleDescriptor.version() instead. Note that the ModuleDescriptor.Version class is Comparable:

Module libraryModule = SomeLibraryClass.class.getModule();
Optional<ModuleDescriptor.Version> libraryVersion =
    libraryModule.getDescriptor().version();

ModuleDescriptor.Version minimumRequiredVersion =
    ModuleDescriptor.Version.parse("2.0");

if (libraryVersion.isPresent() &&
    minimumRequiredVersion.compareTo(libraryVersion.get()) >= 0) {

    System.out.println(libraryModule + " is version " +
        minimumRequiredVersion + " or later.");
}

这篇关于JAR清单文件-规范与实现之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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