Migrate Spring Boot Service from JDK 1.8 to JDK 11 or higher

Step 1. Install OpenJDK 11 and set the JAVA_HOME environment variable. Make sure you check the installed java version by using below mentioned command.

Terminal
1
2
3
4
$ java -version 
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)

Step 2. Update the spring-boot version to the latest. In my case, I have update it to 2.3.3.RELEASE

  • If you are using dependencyManagement use below mentioned code
pom.xml
1
2
3
4
5
6
7
8
9
10
11
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
  • If you are using parent pom then use below mentioned code
pom.xml
1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.3.RELEASE</version>
</parent>

Step 3. Use maven-compiler plugin to compile the code with JDK 11/12

pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Now if you try to build and run the project, you might get one of the below mentioned error

java.lang.NoClassDefFoundError: javax/xml/ws/handler/soap/SOAPHandler

or

java.lang.TypeNotPresentException: Type javax.xml.ws.handler.Handler not present

or

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

The reason why you are getting this error is because 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. Refer this article for more details

Step 4. To resolve this error, add the following dependencies in you pom.xml

pom.xml
1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>

<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>

Step 5. Run the command to build the project

Terminal
1
mvn clean install

Now you should be able to run the project successfully. If you get any error, please comment below in the comment section.

Migrate Spring Boot Service from JDK 1.8 to JDK 11 or higher

https://tutorialflix.com/Migrate-Spring-Boot-Service-from-JDK-1-8-to-JDK-11-or-higher/

Author

Vaibhav Bhootna

Posted on

2020-10-27

Updated on

2020-11-02

Licensed under

Comments