JDK API Diff Report Generator – Java version comparison tool

I checked the information today and found other tools besides EMT4J that can be used for Java version migration.

Just record it briefly here.

If you are not a Java er, please feel free to share your opinions in the comment area.

Introduction to JDK API Diff Report Generator

JDK API Diff is a tool used to compare the API differences of different Java versions. The results will be generated into HTML files. The github address is here.

You can use this tool to compare the API differences between two versions such as OpenJDK 9 and OpenJDK 10, OpenJDK 9 and Oracle JDK 9.

If you don’t want to compile, you can find a comparison of versions of various OpenJDKs in the docs directory of the project. The comparison of some current Java versions is as follows:

Between ITS:

8?11, 8?17, 11?17

between adjacent versions:

8?9, 9?10,…,17?18

Test results

Here we take 8?11 as an example to explain the detection results:

First, a table shows the two versions of the comparison, creation time, which classes are ignored, etc.

Here is a brief explanation of the meaning of the table (not official, my own understanding):

Properties Translation Function
Access modifier filter: PROTECTED Access filter set to “PROTECTED” Unknown
Only modifications: true Only display changes: yes Only the modified parts will be displayed, but not the modified parts. The changed parts will be hidden
Only binary incompatible modifications: false Only binary incompatible modifications are displayed: No Binary is displayed Compatibility and source code compatibility related content
Ignore missing classes: true Ignore non-existent classes: yes
Includes: all Indicates that all packages and classes are included for comparison, and nothing is excluded
Excludes: Excludes some specific packages and classes, which will not be included in the comparison

You can see that this detection result ignores internal classes. I want to see changes in internal classes, so I chose to regenerate the detection results.

Further down are the class detection results, which are generally divided into four types:

  • NEW
  • MODIFIED
  • REMOVED
  • UNCHANGED

They all have literal meanings and are easier to understand. Each of them is divided into two categories. Here is UNCHANGED as an example:

  • UNCHANGED(*)
  • UNCHANGED(!)

Binary-incompatible changes are marked with (!). Source-incompatible changes are marked with (*).

Added: Source Compatibility & Binary Compatibility

Source Code Compatibility:
This compatibility means that the source code of the old version can be compiled successfully in the new version of the compiler without requiring extensive modifications.

Binary Compatibility:
Binary compatibility means that class files (bytecode) compiled using an older version can run normally in a new version of the Java runtime environment without modification.

Classes that have influence or changes are listed here. The blue part on the right is a hyperlink. You can jump to the corresponding class to see detailed information.

Compile

After downloading the project, you need to configure it before compiling.

toolchain

sudo vim ~/.m2/toolchains.xml

Add the following content, because I only plan to compare LTS versions, so I selected three versions: 8, 11, and 17.

If you want to compare other versions, modify the contents in and .

<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
    <toolchain>
        <type>jdk</type>
        <provides>
<version>8</version>
<vendor>openjdk</vendor>
        </provides>
        <configuration>
            <jdkHome>/usr/lib/jvm/java-8-openjdk-amd64</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
<version>11</version>
<vendor>openjdk</vendor>
        </provides>
        <configuration>
            <jdkHome>/usr/lib/jvm/java-1.11.0-openjdk-amd64</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
<version>17</version>
<vendor>openjdk</vendor>
        </provides>
        <configuration>
            <jdkHome>/usr/lib/jvm/java-1.17.0-openjdk-amd64</jdkHome>
        </configuration>
    </toolchain>
</toolchains>

pom.xml

Modify the contents in and to change the two jdk versions to be compared. Only the version configured in toolchains.xml can be selected.

Ignored part

The ignored part is the part outlined in red. You can see that the default is the annotation state, and there is no need to add it here.

Compile statement

mvn clean install

The project will package all corresponding jdk versions into jar packages, and generate differential HTML by comparing the differences in the jar packages.

Problems encountered

Missing header in: jdk-api-diff/LICENSE.txt

I didn’t find out this either, so I solved it by unchecking the license-maven-plugin in pom.xml.

java.io.FileNotFoundException: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/javaws.jar

The version tested in the project is 8u301, and the version I am currently using is 8u382. There are some differences in the jdk, so there will be this error.

Comment out the relevant code here to solve the problem.

ps: jfxrt.jar is commented out because this also reports an error, and the error message is no longer pasted here.

Compilation results

The comparison results are in the target directory, jdk-api-diff.html.

The result is nearly 200m, which is much more than the 50m in the example.

As you can see, there are internal classes in this detection result.

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 138432 people are learning the system