JAR Manifest file - Difference between Specification and Implementation

Joachim Kurz

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.

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

VGR

The meaning of each is explained in the documentation of java.lang.Package.

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

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.

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.");
}

Update

The above will not work in a Java 9 modular application. From the documentation for 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 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.");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Difference between Java implementation and UML specification wrt interfaces and abstract classes

From Dev

Difference between plugin and external jar file

From Dev

Confusion on Uses of Jar Manifest File

From Dev

Implementation of jar file

From Dev

Difference Between Declaring a Variable Under @Implementation And @Interface Under .m file

From Dev

Difference Between Declaring a Variable Under @Implementation And @Interface Under .m file

From Dev

no main manifest attribute (But I have the manifest file in the jar)

From Dev

Exporting Jar file with Manifest attribute in Android Studio?

From Java

Replacing the MANIFEST.MF file in a JAR programmatically

From Dev

Using Java to read a .jar manifest file

From Dev

Jar command not adding requested manifest file to archive

From Dev

JAR file manifest does not contain permission attribute

From Dev

Using Java to read a .jar manifest file

From Dev

add manifest to compiled exe file from jar

From Dev

"-includeresource" in JAR Manifest inside Gradle build file

From Dev

The difference between Aggregation and Association in implementation

From Dev

Difference between std::forward implementation

From Dev

Error opening zip file or JAR manifest missing : jrebel.jar

From Dev

Difference between "file:///" and "file://"

From Dev

Difference between "file:///" and "file://"

From Java

Difference between jar and war in Java

From Dev

In Objective-C, what's difference between import in header file and implementation file?

From Dev

How to configure a manifest file of a jar file by using the maven assembly plugin?

From Dev

Is there any difference between noexcept and empty throw specification for an lambda expression?

From Dev

Difference Between Test Design Specification and Test Design Document

From Dev

Difference between POSIX, Single UNIX Specification, and Open Group Base Specifications?

From Dev

Difference Between toPredicate() Method and And/Or/Not/Where in JPA Criteria API Specification<>

From Dev

Difference between datetimes in a file

From Dev

What is the proper way to parse the entries of a manifest.mf file in jar?

Related Related

  1. 1

    Difference between Java implementation and UML specification wrt interfaces and abstract classes

  2. 2

    Difference between plugin and external jar file

  3. 3

    Confusion on Uses of Jar Manifest File

  4. 4

    Implementation of jar file

  5. 5

    Difference Between Declaring a Variable Under @Implementation And @Interface Under .m file

  6. 6

    Difference Between Declaring a Variable Under @Implementation And @Interface Under .m file

  7. 7

    no main manifest attribute (But I have the manifest file in the jar)

  8. 8

    Exporting Jar file with Manifest attribute in Android Studio?

  9. 9

    Replacing the MANIFEST.MF file in a JAR programmatically

  10. 10

    Using Java to read a .jar manifest file

  11. 11

    Jar command not adding requested manifest file to archive

  12. 12

    JAR file manifest does not contain permission attribute

  13. 13

    Using Java to read a .jar manifest file

  14. 14

    add manifest to compiled exe file from jar

  15. 15

    "-includeresource" in JAR Manifest inside Gradle build file

  16. 16

    The difference between Aggregation and Association in implementation

  17. 17

    Difference between std::forward implementation

  18. 18

    Error opening zip file or JAR manifest missing : jrebel.jar

  19. 19

    Difference between "file:///" and "file://"

  20. 20

    Difference between "file:///" and "file://"

  21. 21

    Difference between jar and war in Java

  22. 22

    In Objective-C, what's difference between import in header file and implementation file?

  23. 23

    How to configure a manifest file of a jar file by using the maven assembly plugin?

  24. 24

    Is there any difference between noexcept and empty throw specification for an lambda expression?

  25. 25

    Difference Between Test Design Specification and Test Design Document

  26. 26

    Difference between POSIX, Single UNIX Specification, and Open Group Base Specifications?

  27. 27

    Difference Between toPredicate() Method and And/Or/Not/Where in JPA Criteria API Specification<>

  28. 28

    Difference between datetimes in a file

  29. 29

    What is the proper way to parse the entries of a manifest.mf file in jar?

HotTag

Archive