Skip to content

Instantly share code, notes, and snippets.

@mondain
Created January 8, 2021 16:25
Show Gist options
  • Save mondain/f74a1969ca2b547faea9efda2cebc993 to your computer and use it in GitHub Desktop.
Save mondain/f74a1969ca2b547faea9efda2cebc993 to your computer and use it in GitHub Desktop.
JDK upgrade notes

JDK Update

Code Differences

Between JDK 8 and JDK 11 a lot has changed, mostly around modularization of the JDK in JDK 9. A few examples below cover method changes between our primary JDK versions:

  • Getting a new instance via reflection. The getDeclaredConstructor() is expected, ex. Class.forName(serviceName).getDeclaredConstructor().newInstance()
  • Deprecation of the finalize() method
  • Forced boxing is frowned upon and flagged in the IDE new Integer(13) or new Boolean(true) should not be used. The base type is expected instead.

Native Dependencies

Native libs built with JDK 8 continue to work with JDK 11. Conversion of native dependencies to JDK 11 for build eclusivity will take a bit more time, but should not preclude the server proper from being upgraded.

CI

Our TeamCity agents have 8 and 11 on them. To target a particular JDK you would have to change the JAVA_HOME param for the build: http://54.174.142.30:8111/admin/editBuildParams.html?id=buildType:Red5ProServer_Red5ProFeatureStaging ex. switching to JDK 11: /usr/lib/jvm/java-11-openjdk-amd64

Tomcat should be set to version 8.5.61 and the Red5 Tomcat plugin to version 2.2.8.

JDK Path Reference

Additional JDK paths on Ubuntu as follows:

  • OpenJDK 8: /usr/lib/jvm/java-8-openjdk-amd64
  • Amazon Corretto 8: /usr/lib/jvm/java-1.8.0-amazon-corretto
  • OpenJDK 11: /usr/lib/jvm/java-11-openjdk-amd64
  • Amazon Corretto 11: /usr/lib/jvm/java-11-amazon-corretto

References

@mondain
Copy link
Author

mondain commented Jan 10, 2021

TeamCity has /usr/lib/jvm/java-8-oracle set in parameters

@mondain
Copy link
Author

mondain commented Jan 10, 2021

Have Todd make sure Stringer works with JDK 11 and is best version

@mondain
Copy link
Author

mondain commented Jan 10, 2021

@mondain
Copy link
Author

mondain commented Jan 11, 2021

@mondain
Copy link
Author

mondain commented Jan 11, 2021

When a build error for a webapp fails, update the war plugin version and if it also includes failure to find apache http, add the dependency

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>provided</scope>
        </dependency>

@mondain
Copy link
Author

mondain commented Jan 11, 2021

Proguard configs also have to be updated, mostly to exclude jigsaw modules like so:

-libraryjars  <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.desktop.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.net.http.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.instrument.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.logging.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.management.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.se.jmod(!**.jar;!module-info.class)
-libraryjars  <java.home>/jmods/java.xml.jmod(!**.jar;!module-info.class)

@mondain
Copy link
Author

mondain commented Jan 11, 2021

TeamCity

JDK 11

target_feature_branch=feature/RPRO-5465
target_frontend_branch=feature/RPRO-5465
tomcat_apache_version=8.5.61
tomcat_version=2.2.8
system.java_target=11
system.red5_client_target=1.2.6
system.red5_target=1.2.6
env.JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

JDK 8

target_feature_branch=feature/greatdane08-tc
target_frontend_branch=feature/auto-greatdane04
tomcat_apache_version=8.5.61
tomcat_version=2.2.6
system.java_target=8
system.red5_client_target=1.1.1
system.red5_target=1.1.1
env.JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

@mondain
Copy link
Author

mondain commented Jan 13, 2021

For Native builds, javah has to be excluded since it was completely removed in JDK 10.

On the compile plugin (see compiler args):

               <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <executions>
                        <execution>
                            <id>default-compile</id>
                            <configuration>
                                <!-- compile everything to ensure module-info contains right entries -->
                                <release>${java.release.level}</release>
                            </configuration>
                        </execution>
                        <execution>
                            <id>base-compile</id>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                            <!-- recompile everything for target VM except the module-info.java -->
                            <configuration>
                                <excludes>
                                    <exclude>module-info.java</exclude>
                                </excludes>
                            </configuration>
                        </execution>
                    </executions>
                    <!-- defaults for compile and testCompile -->
                    <configuration>
                        <!-- Only required when JAVA_HOME isn't at least Java 9 and when haven't configured the maven-toolchains-plugin -->
                        <jdkToolchain>
                            <version>11</version>
                        </jdkToolchain>
                        <verbose>true</verbose>
                        <release>${java.release.level}</release>
                        <compilerArgs>
                            <arg>-h</arg>
                            <arg>${project.build.directory}/nar/javah-include</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>

On the nar plugin:

                <plugin>
                    <groupId>com.github.maven-nar</groupId>
                    <artifactId>nar-maven-plugin</artifactId>
                    <version>3.10.1</version>
                    <executions>
                        <execution>
                            <id>default-nar-javah</id>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment