I have recently started working on creating a REST API for a client project. I was using Java 8 for my past developments. Since Java 11 was introduced in the last September
(https://en.wikipedia.org/wiki/Java_version_history) I thought of developing the REST API in Java 11.
Java 11 is having major changes after Java 8. Java 11 is having a concept of modules (This was introduced after Java 9). Several libraries are acting as separate modules. Those are not included in JDK and those have to be imported separately.
Ref : http://openjdk.java.net/jeps/261
(I have experienced this in JBoss7 also. They were using the module system and each service can specify which modules which are using. Those modules can be manually configured by the user.)
One example is that you have to import the Java fx library separately (For GUI). Java-Fx is decoupled from JDK.
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11-ea+19</version>
</dependency>
The second example, which is related to my SPRING REST API is that I had the following experience while testing my API.
"nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException". I had knowledge that Java 11 is using the module system. But I haven't checked all the changes compared to Java 8. This is my initial understanding of Java 11.
The JAXB APIs are considered to be Java EE APIs and therefore are no longer contained on the default classpath in Java SE 9. In Java 11 they are completely removed from the JDK.
Java 9 introduces the concepts of modules, and by default, the java.se aggregate module is available on the classpath (or rather, module path). As the name implies, the java.se aggregate module does not include the Java EE APIs that have been traditionally bundled with Java 6/7/8.
The Java EE API modules listed above are all marked @Deprecated(forRemoval=true), because they are scheduled for removal in Java 11. So the --add-module approach will no longer work in Java 11 out of the box.
Ref: http://openjdk.java.net/jeps/320
What you will need to do in Java 11 and forward is include your own copy of the Java EE APIs on the class path or module path. For example, you can add the JAX-B APIs as a maven dependency like this:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
For full details on Java modularity, see JEP 261: Module System
Comments
Post a Comment