Java applications have to deal with JDK upgrades. On the one hand, it is expected that Java applications can keep up with the latest JDK versions.
On the other hand, the JDK upgrade of Java applications is slow. It has been nearly four years since JDK 11 was released in 2018. The upgraded JDK 11 has not reached half (2022-state-of-java-ecosystem). In contrast, JDK 8 reached 38% within one year of its release, 64.3% within two years, and nearly 80% by 2018 (java-8-adoption-march-2016, jvm-ecosystem-report-2018).
There are many possible reasons. For example, JDK 8 introduces Lambda at the language level, which is attractive to developers. The JDK 11 update at the language level is optional. However, compared with upgrading from other versions to JDK 8 (upgrading from JDK 6/7 to JDK 8 is insensitive to applications), upgrading to JDK 11/17 will be much more difficult, and there will be many compatibility problems. For example:
If the applications that need to be upgraded depend on hundreds of two-party and three-party JAR, these JARs may also have compatibility problems. If dozens or even hundreds of applications need to be upgraded, the additional workload can be huge.
Due to these difficulties, Alibaba has accumulated these upgrade experiences through tools to help Java applications upgrade to the latest version of JDK efficiently.
Currently, Eclipse Migration Toolkit for Java (EMT4J) is open source in the Eclipse community and has passed the Eclipse Adoptium PMC review. It is incubated as an Eclipse Adoptium sub-project. Alibaba Cloud is also a cornerstone member of the Eclipse Adoptium working group. It participates in the Eclipse Adoptium community governance and provides fully compatible, OpenJDK-based, high-quality JDK distributions for the Java Ecosystem.
EMT4J currently supports the analysis of upgrading from JDK 8 to JDK 11 & 17. It will continue to update the support for the latest LTS versions in the future.
Currently, you can use the following three methods:
The following is the EMT4J architecture diagram:
Let's take a common scenario to demonstrate the use of the tool:
Developer Tom received a task that required him to upgrade eight Java applications (app-service-1 to app-service-8) that his team was responsible for from JDK 8 to JDK 17. How did he upgrade with the help of EMT4J?
The specific upgrade operation is divided into the following seven steps:
1. Tom downloaded the EMT4J tool to the /home/jdk17
and installed the target version of JDK 17.
2. He downloaded the app-service-1~app-service-8
application package to the machine where EMT4J is located and put it in /home/app/deploy
directory. He put the JVM options app-service-1~app-service-8
into the text file of .cfg
in the /home/app/vmoptions
directory.
3. He ran a tool check: sh ${EMT4J_HOME}/bin/analysis.sh -f 8 -t 17 -j /home/jdk17 /home/app
, where -f 8 -t 17
indicates the upgrade from 8 to 17, -j /home/jdk17
indicates the installation directory of the target version JDK, and /home/app
indicates the application package and parameter file to be checked. After the command is executed, report.html is generated in the current directory by default. Open the check report report.html to view the following list of problems:
4. Tom clicked "The schema of java version changed in JDK9" to view the details of the problem and saw the following specific classes: Location: file:/home/app/deploy/app-service-1/notify-utils-2.2.5.jar, Target: com.app.services1.utils.VersionInfo
.
5. Tom opened the app-service-1
project and saw the following code. The following code cannot handle a version number similar to 17.0.1.
private final String JAVA_VERSION = System.getProperty("java.version");
private final int getJavaVersionAsInt() {
if (this.JAVA_VERSION == null)
return 0;
String str = this.JAVA_VERSION.substring(0, 1);
str = str + this.JAVA_VERSION.substring(2, 3);
if (this.JAVA_VERSION.length() >= 5) {
str = str + this.JAVA_VERSION.substring(4, 5);
} else {
str = str + "0";
}
return Integer.parseInt(str);
}
6. Tom referred to how to fix it in the report and learned that the schema of Java Version has changed since JDK 9. He modified the code according to the new schema.
7. Tom revised other issues in the reference report in turn. After the modification is completed, he used the target version JDK startup on the development machine to verify the correctness of the function.
The preceding EMT4J tool helped Tom upgrade from JDK 8 to JDK 17. What are the features of the EMT4J tool?
JDK 8 to JDK 11
JDK 11 to JDK 17
If you encounter the following problems when using EMT4J:
You can participate in the contribution in the following ways:
Currently, there are many Java applications still on JDK 8, and these applications are planning or upgrading to JDK. We hope to make the upgrade easier through EMT4J.
We have accumulated Alibaba's experience in upgrading JDK in the tool, but there are many compatibility problems that we have not encountered. In addition, new JDK versions will be released continuously, and new compatibility problems will continue to arise. We hope more developers can participate and enhance the functions of the tool through open-source, making it easier to upgrade Java applications. Please refer to this link for more details about how to use, contribute, etc.
OpenAnolis Launches "Hierarchical Classification" to Develop Open-Source Industry Innovation Ecology
85 posts | 5 followers
FollowAlibaba Cloud Native Community - September 12, 2023
Alibaba Clouder - November 15, 2019
Alibaba Cloud Community - March 16, 2023
OpenAnolis - April 20, 2022
Alibaba Clouder - January 28, 2019
Alibaba Developer - January 29, 2021
85 posts | 5 followers
FollowThis solution helps you improve and secure network and application access performance.
Learn MoreAccelerate and secure the development, deployment, and management of containerized applications cost-effectively.
Learn MoreAn easy transformation for heterogeneous database.
Learn MoreBuild business monitoring capabilities with real time response based on frontend monitoring, application monitoring, and custom business monitoring capabilities
Learn MoreMore Posts by OpenAnolis