This topic describes how to fix the Java Development Kit (JDK) version in the process of changing an ECS application. This way, new Elastic Compute Service (ECS) instances that are created for the application during a scale-out use the same JDK version as existing ECS instances for the application.
Background information
By default, the latest version of OpenJDK is installed on ECS instances that are imported an ECS cluster in EDAS. However, existing ECS instances for an application may not use the latest version of OpenJDK. As a result, new ECS instances that are created for the application during a scale-out may use a JDK version different from that on existing ECS instances for the application. This causes exceptions during the execution of business code.
You can fix the JDK version during an ECS application change to prevent such exceptions. You can add a code snippet to be executed to the pre-launch script in mount scripts. In the code snippet, you can specify the download URL of JDK of the specified version. This way, the JDK version remains unchanged on ECS instances for the application during an application change, such as a scale-out or restart.
Procedure
Obtain the download URL of JDK of the specified version.
Download the JDK package of the specified version, such as oracle-jdk-8u202-linux-x64.tar.gz, to your on-premises computer.
Upload the JDK package to an Object Storage Service (OSS) bucket in the same region as the ECS instances for the ECS application. For more information, see Upload objects.
Obtain the download URL of the JDK package and add -internal to the download URL. For more information about how to obtain the download URL, see Share objects.
For example, the download URL of oracle-jdk-8u202-linux-x64.tar.gz is http://doctest.oss-cn-hangzhou-internal.aliyuncs.com/tmp/oracle-jdk-8u202-linux-x64.tar.gz.
Add the download URL of the JDK package to the code snippet.
Set the JDK_DOWNLOAD_URL variable in the following code snippet to the download URL of the JDK package:
JDK_DOWNLOAD_URL="http://doctest.oss-cn-hangzhou-internal.aliyuncs.com/tmp/oracle-jdk-8u202-linux-x64.tar.gz" JDK_DOWNLOAD_TMP_FILE="/tmp/oracle-jdk-8u202.tar.gz" JDK_HOME="/opt/edas/jdk" JAVA_HOME="${JDK_HOME}/java" if [ ! -f "${JAVA_HOME}/bin/java" ]; then rm -rf ${JAVA_HOME} && mkdir -p ${JDK_HOME} wget -q --dns-timeout=2 --connect-timeout=3 --read-timeout=30 ${JDK_DOWNLOAD_URL} -O ${JDK_DOWNLOAD_TMP_FILE} [ -f "${JDK_DOWNLOAD_TMP_FILE}" ] && tar zxf ${JDK_DOWNLOAD_TMP_FILE} -C ${JDK_HOME} && rm -f ${JDK_DOWNLOAD_TMP_FILE} [ -n "$(ls -ld ${JDK_HOME}/jdk* 2>/dev/null)" ] && mv ${JDK_HOME}/jdk* ${JAVA_HOME} fi chmod -R 755 ${JAVA_HOME}Add the preceding code snippet to the pre-launch script of the ECS application.
Log on to the EDAS console.
In the left-side navigation pane, click Applications. In the top navigation bar, select the region in which the application resides. In the upper part of the Applications page, select the microservice namespace in which the ECS application resides. Then, find the ECS application and click the name of the ECS application.
In the Application Settings section of the Basic Information tab, click Mount Script.
In the Pre-launch Script section of the Mount Script dialog box, turn off Ignore failed, add the code snippet that you prepared in Step 2, and then click Modify.

Restart the ECS application. Check whether the JDK version of the ECS application is the same as that specified.
NoteAfter the ECS application is restarted, you can also log on to an ECS instance for the application and check whether the JDK version is the same as that specified.
Additional information
If you want to use the specified version of OpenJDK, add the command yum install -y fontconfig for installing the fontconfig library to the code snippet in the pre-launch script.
If the ECS application needs to use JDK 11 or JDK of the specified version from another vendor, you can also configure a mount script to install JDK of the specified version to the /opt/edas/jdk/java or /opt/ali/alijdk directory. This is another method to fix the JDK version.