How can we create a multi-release jar(mrjar) using jar tool in Java 9?

JavaObject Oriented ProgrammingProgramming

In Java 9, a new feature "multi-release jar format" has been introduced where jar format enhanced with different versions of Java class or resources that can be maintained and used as per the platform. A jar command can be used to create a multi-release jar that contains two versions of the same class compiled for both Java 8 and Java 9 versions with a warning message, telling that both classes are identical.

C:\Users\User\tutorialspoint>jar --create --file MR.jar -C sampleproject-base demo --release 9 -C sampleproject-9 demo
Warning: entry META-INF/versions/9/demo/SampleClass.class contains a class thatis identical to an entry already in the jar

The " --release 9" option can tell jar to include everything that can follow (the demo package inside "sampleproject-9 "directory) inside a versioned entry in the MRJAR under "root/META-INF/versions/9".

jar root
   - demo
      - SampleClass.class
      - versions
         - 9
            - demo
               - SampleClass.class
Published on 01-Apr-2020 19:59:09