- Java 9 - Miscellaneous Features
- CompletableFuture API Improvements
- Java 9 - Multiresolution Image API
- Optional Class Improvements
- Inner Class Diamond Operator
- Enhanced @Deprecated Annotation
- Try With Resources improvement
- Java 9 - Stream API Improvements
- Java 9 - Process API Improvements
- Java 9 - Private Interface Methods
- Java 9 - Collection Factory Methods
- Java 9 - Multirelease JAR
- Java 9 - Improved JavaDocs
- Java 9 - REPL (JShell)
- Java 9 - Module System
- Java 9 - Environment Setup
- Java 9 - Overview
- Java 9 - Home
java9 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 9 - Multirelease JAR
In java 9, a new feature is introduced where a jar format has been enhanced to have different versions of java class or resources can be maintained and used as per the platform. In JAR, a file MANIFEST.MF file has a entry Multi-Release: true in its main section. META-INF directory also contains a versions subdirectory whose subdirectories (starting with 9 for Java 9 ) store version-specific classes and resource files.
In this example, we ll be using a multi-release jar to have two versions of Tester.java file, one for jdk 7 and one for jdk 9 and run it on different jdk versions.
Steps
Step 1 − Create a folder c:/test/java7/com/tutorialspoint. Create Test.java with following content −
Tester.java
package com.tutorialspoint; pubpc class Tester { pubpc static void main(String[] args) { System.out.println("Inside java 7"); } }
Step 2 − Create a folder c:/test/java9/com/tutorialspoint. Create Test.java with following content −
Tester.java
package com.tutorialspoint; pubpc class Tester { pubpc static void main(String[] args) { System.out.println("Inside java 9"); } }
Compile the source codes.
C: est > javac --release 9 java9/com/tutorialspoint/Tester.java C:JAVA > javac --release 7 java7/com/tutorialspoint/Tester.java
Create the multi-release jar
C:JAVA > jar -c -f test.jar -C java7 . --release 9 -C java9. Warning: entry META-INF/versions/9/com/tutorialspoint/Tester.java, multiple resources with same name
Run with JDK 7
C:JAVA > java -cp test.jar com.tutorialspoint.Tester Inside Java 7
Run with JDK 9
C:JAVA > java -cp test.jar com.tutorialspoint.Tester Inside Java 9Advertisements