Installing Oracle JDK and Tomcat on an EC2 Linux instance

Installing Java JDK on Amazon Linux AMI

Most likely you already have Open JDK installed on you EC2 instance. You will have replace OpenJDK with Oracle JDK. Here is how you do it.

Perform all the operations below as root.Get the latest Oracle (Sun) JDK rmp binary from the Oracle website and copy it to the EC2 instance.

# make it exec
chmod +x jdk-6u34-linux-x64-rpm.bin

# Install Java
sudo ./jdk-6u34-linux-x64-rpm.bin

# Check if the default java version is set to sun jdk
# Normally it says OpenJDK
java -version

# Create another alternative for Java for Sun JDK
sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_34/bin/java 20000

# Set the SUN JDK as the default java
sudo /usr/sbin/alternatives --config java

# Verify if change in SDK was done.
java -version

Installing Tomcat on Amazon Linux AMI

# Check if tomcat is already installed 
yum info tomcat6

# To install tomcat6, run the following command
yum install tomcat6

# Start Tomcat as follows
service tomcat6 start

Tomcat has now been installe in /usr/share/tomcat6/

# To check that Tomcat has indeed started and is listening on port 8080:
fuser -v -n tcp 8080

#To have Tomcat start automatically on instance reboot
chkconfig --level 345 tomcat6 on 

Tomcat by default runs on port 8080. Traffic can be redirected from port 80 to 8080 by running the following commands:

/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
/sbin/service iptables save

One thought on “Installing Oracle JDK and Tomcat on an EC2 Linux instance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s