If your application requires a different JDK than what we provide with the Apache Tomcat AMIs (Oracle JDK, IBM JDK, different JDK version), you can take the following steps to reconfigure Tomcat. (Please make sure the JDK you intend to use is supported by Tomcat.)
If you are able to use OpenJDK:
Login to the instance
Stop the Tomcat service by running:
sudo systemctl stop tomcat
Remove the existing OpenJDK packages by running:
yum remove -y java-1.8.0-openjdk-headless
Install the desired OpenJDK packages by running the command associated with the JDK version you need:
yum install -y java-1.7.0-openjdk-headless
yum install -y java-1.8.0-openjdk-headless
yum install -y java-11-openjdk-headless
(If you prefer the full JDK, remove "-headless" from the commands above)Start the Tomcat service by running:
sudo systemctl start tomcat
Test your instance to ensure it is still operating as expected.
If confirmed to be working, these steps can be incorporated into a user-data script to automate this process.
If you require Oracle or IBM JDK:
Due to licensing restrictions, we cannot ship Oracle or IBM products with our AMIs. If you are licensed to use these products, you can deploy them to our AMIs using the following steps:
Download the JDK from your vendor
Copy the JDK to your EC2 instance
Stop the Tomcat service by running:
systemctl stop tomcat
Remove the existing OpenJDK packages by running:
yum remove -y java-1.8.0-openjdk-headless
Install your JDK into the directory you desire. Using Oracle as an example:
cd /opt
tar xzf jdk-8u221-linux.tar.gz
# Package installed into /opt/jdk-1.8.0_221Edit the /usr/lib/systemd/system/tomcat.service file and modify the highlighted lines to point to your JDK:
[Service] User=tomcat WorkingDirectory=/opt/tomcat Environment=JRE_HOME=/opt/jdk-1.8.0_221/jre Environment=JAVA_HOME=/opt/jdk-1.8.0_221/jre Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINE_BASE=/opt/tomcat
Start the Tomcat service by running:
systemctl start tomcat
If Tomcat fails to start, examine the /var/log/tomcat/catalina.out file for error messages.
If confirmed to be working, these steps can be incorporated into a user-data script (using an S3 bucket to store your JDK package) to automate this process.