Skip to main content

Java 11 Modularity and Spring REST


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

Popular posts from this blog

SVN to GIT Migration with revision history

This blog explains the process I have followed while moving one of code branch of one of the projects to Gitlab. SVN to Git migration can be done using the git-svn command in Git.  Documentation about this command can be found from here. https://git-scm.com/docs/git-svn My Company svn repository can be accessed using two ways svn+ssh://192.168.x.x/usr/local/ svnroot/branches/PROJECT/PROJECT_BRANCH http://svn.companyName.net/repos/svnroot/branches/ PROJECT/PROJECT_BRANCH SVN to GIT migration can be done using one of the above-mentioned URLs.  Git can be installed and configured to use its inbuilt SSH client or third party ssh client ( https://6xgate.github.io/TortoisePlink/ ) First of all, this process should be run in a server where the system does not go idle. I have tried this on my PC. But when I have locked the PC, it crashes. Therefore I have tried this in one of our internal server. I have tried to get SVN revision history when the P...

President - Association of Computer Engineering Students

I was selected to be the president of ACES, Association of Computer Engineering Students, the official student body of the Department of Computer Engineering Students. ACES Site :  aces.ce.pdn.ac.lk  It was a great opportunity to work with fellow undergraduates, lecturers, senior graduates, and industry. Until now We were able to organize few events in University of Peradeniya and Colombo. This event was organized by ACES Council, a group of 14 undergraduates. The events are, ACES Hackathon - This is an inner hackathon for undergraduates in the University of Peradeniya. ACES Hackathon, held annually for the last 5 years was held from the 29th of April to the 1st of May 2016 at the Faculty of Engineering, University of Peradeniya. The Hackathon brings together undergraduates from the Faculty of Engineering and Science for 3 days to develop their creative skills to provide innovative IT solutions. This year there were 150+ participants.   www.readme.lk/saw-ac...