Upgrading Legacy Java Web Application to JDK 11

Java 11 (https://openjdk.java.net/projects/jdk/11/) was released on 25 September 2018, so I’ve decided I’ll upgrade my legacy Java web application that was written at times of Java 6. Even two month after the release, surprisingly, the tooling is not mature enough.

My application is RSS reader that I wrote at times of Google Reader decommissioning. It was written in NetBeans and it uses Java SE for back-end, which uses XML parse, JSON parser, and REST resources. Front-end is simple JavaScript enabled static page. I use very simple ant-based build steps.
So, I thought it would be simple task.


As part of the upgrade process I wanted to upgrade whole project to Spring Boot 2, mainly to get OAuth2, database APIs and other goodies for free. As a build system I decided for Gradle.

First, I downloaded OpenJDK 11 (Oracle JDK is not free to use any more!). It must be unpacked manually and sourced on your PATH.

Then I downloaded Eclipse IDE 2018‑09 and added JDK 11 plug-in from Marketplace to enable JDK 11 support. Initially, I used Gradle 4.10.2.

Project was not compiling initially as JAXB and javax.activation APIs were missing. This was fixed by adding the following dependencies:

compile 'javax.xml.bind:jaxb-api'
compile 'com.sun.xml.bind:jaxb-core:2.3.0.1'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'com.sun.activation:javax.activation:1.2.0'

As a next step, I tried to make all junit tests running. There I saw weird error message that Gradle cannot find a test class that was visibly compiled. After bit of Google I found I need Gradle 5.0 which was not released yet. Fortunately, version 5.0 RC3 is working well and it sorted all of my problems.

For reference you can find my build.gradle below.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'java'
    id 'eclipse'
}

apply plugin: 'checkstyle'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'app'
    version =  '1.0.0'
}

repositories {
    mavenLocal()
    mavenCentral()
}

group = 'com.example'
version = '1.0.0'

sourceCompatibility = 11.0
targetCompatibility = 11.0

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-oauth2-client")
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('com.h2database:h2')
    
    compile 'commons-fileupload:commons-fileupload:1.3.3'
    compile 'org.apache.commons:commons-lang3:3.8.1'
    compile 'org.jsoup:jsoup:1.11.3'
    compile 'javax.mail:javax.mail-api:1.6.2'
    
    compile 'javax.xml.bind:jaxb-api'
    compile 'com.sun.xml.bind:jaxb-core:2.3.0.1'
    compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
    compile 'com.sun.activation:javax.activation:1.2.0'
    
    testCompile("junit:junit")
}

Final Thoughts

My believe is that Java release process is too fast for reasonable usage. I expect programming language to be stable including it’s tooling. When we have new Java every 6 months, all tools and libraries need to be prepared for the new Java release. And I don’t think it’s the case as two month after the GA we are not there yet. It’s also good to mention Java 8 (last LTS release) should be ended support on January 2019, which is damn close.

Based on my thought it seems Oracle is pushing corporate customers on paid support model. This might buy more time for migration between Java LTS releases.

Addition (18th December 2018)

There is another really nice article on Spring Boot migration from JDK 8 to 11 at https://dzone.com/articles/migrating-springboot-applications-to-latest-java-v