Installing OpenJDK 11 Instead of JDK 1.8 for a Java Application on Windows
Introduction
Java Development Kit (JDK) 1.8 has been a popular choice for Java developers for many years. However, as of September 2022, Oracle has ended its free public updates for JDK 8, making it necessary for developers to consider migrating to a more recent version. OpenJDK 11 is a popular alternative to JDK 1.8 and offers several benefits, including long-term support, improved performance, and new features. In this article, we will discuss the steps required to install OpenJDK 11 on a Windows system and use it for a Java application instead of JDK 1.8.
Prerequisites
Before we begin, it is assumed that you have the following:
- A Windows operating system installed on your computer.
- A Java application that is currently using JDK 1.8.
- Basic knowledge of the command prompt and Java programming.
Step 1: Download OpenJDK 11
The first step is to download OpenJDK 11. There are several vendors that provide OpenJDK 11 builds, including Adoptium, Amazon Corretto, and Zulu. For this article, we will use the Adoptium build, which is available for download from the following link:
Once you are on the Adoptium website, select the Windows operating system and the OpenJDK 11 version. Then, click on the "Download" button to download the installer.
Step 2: Install OpenJDK 11
After downloading the installer, double-click on it to start the installation process. Follow the prompts to complete the installation. Once the installation is complete, you can verify the installation by opening a command prompt and running the following command:
java -version
This should display the OpenJDK 11 version number, as shown below:
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Adoptium (build 11.0.15+10)
OpenJDK 64-Bit Server VM Adoptium (build 11.0.15+10, mixed mode)
Step 3: Configure the Java Environment Variables
The next step is to configure the Java environment variables to use OpenJDK 11. To do this, follow these steps:
- Open the Start menu and search for "Environment Variables".
- Click on "Edit the system environment variables".
- In the System Properties window, click on the "Environment Variables" button.
- Under "System variables", scroll down and find the "Path" variable.
- Click on "Edit" and add the path to the OpenJDK 11 "bin" directory. The default path is "C:\Program Files\Adoptium\jdk-11.0.15.10-hotspot\bin".
- Click on "OK" to save the changes.
Step 4: Verify the Java Environment Variables
To verify that the Java environment variables have been configured correctly, open a new command prompt and run the following command:
java -version
This should display the OpenJDK 11 version number, as shown in Step 2.
Step 5: Update the Java Application to Use OpenJDK 11
The final step is to update the Java application to use OpenJDK 11. This can be done by modifying the build script or the project configuration to use the OpenJDK 11 "bin" directory.
For example, if you are using Maven as the build tool, you can update the "maven-compiler-plugin" configuration in the pom.xml file to use OpenJDK 11, as shown below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<fork>true</fork>
<executable>C:\Program Files\Adoptium\jdk-11.0.15.10-hotspot\bin\java.exe</executable>
</configuration>
</plugin>
</plugins>
</build>
Conclusion
In this article, we have discussed the steps required to install OpenJDK 11 on a Windows system and use it for a Java application instead of JDK 1.8. We have covered the prerequisites, downloading OpenJDK 11, installing OpenJDK 11, configuring the Java environment variables, verifying the Java environment variables, and updating the Java application to use OpenJDK 11. By following these steps, you can ensure that your Java application is using a supported and up-to-date version of the JDK.
References
- Adoptium: https://adoptium.net/
- Amazon Corretto: https://aws.amazon.com/corretto/
- Zulu: https://www.azul.com/downloads/zulu-community/