Search code examples
javatomcatamazon-web-servicesamazon-ec2catalina

Apache Tomcat in Amazon EC2 Error: could not find org.apache.catalina.util.ServerInfo


I have followed the installation guide available here: http://www.excelsior-usa.com/articles/tomcat-amazon-ec2-basic.html

I am running an AWS EC2 instance with the Amazon Linux AMI (Amazon Machine Image): Amazon Linux AMI 2014.03.2 (HVM) - ami-d13845e1

I have installed Java 7 on the machine:

${JAVA_HOME}/bin/java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (amzn-2.5.1.2.43.amzn1-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

And I've installed Tomcat7. When I started up the server and try to connect to my machine's address on port 8080, I get a blank page or the request simply hangs. I have installed all of the Tomcat7 packages (see step #5 in the article linked at start of this post) and so I should be seeing the default Tomcat home page (I'd even be happy with a 400 response code!)

I can confirm that my security group is correct (I've previously run Jetty from port 8080 with this same security group). I also followed the guide's command to check if tomcat7 is running and listening to port 8080:

$ sudo fuser -v -n tcp 8080 
                     USER        PID ACCESS COMMAND
8080/tcp:            tomcat     1669 F.... java

When I attempted to run the version command, I got a very strange response:

$ sudo service tomcat7 version
/usr/sbin/tomcat7: line 21: .: /etc/sysconfig/: is a directory
/usr/sbin/tomcat7: line 25: cd: HOME not set
Error: Could not find or load main class org.apache.catalina.util.ServerInfo

I've tried to Google around for solutions and I tried stuff like this but nothing has resulted in success. I'm not sure if the above message I'm receiving from version is related to why my tomcat7 isn't working but it is the only thing I can think of to try and troubleshoot.

Has anyone experiences similar? Does anyone have ideas of what might be wrong? Anyone else sad when they follow a wonderful guide to do something 'easy' and it still doesn't work? :-P

As a side note, I have installed Tomcat7 successfully on my local Windows7 machine via the .exe file and it works beautifully. I'm trying to develop locally and then push to my Amazon Web Service but it seems like I have to solve this problem first.


Solution

  • I can confirm the issue you are facing. However, I got it working just fine using Oracle JDK. I followed these steps:

    create an instance from ami-d13845e1

    removed the existing OpenJDK: yum -y remove java-1.7.0-openjdk

    Download and installed Oracle JDK: http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.rpm

    Note: downloading Oracle JDK itself is pain. it’s just not fun downloading it using Linux wget command. Oracle forces you to accept the terms and conditions. So figure out your own way of downloading that file.

    Installed the Oracle JDK: rpm -ivh jdk-7u65-linux-x64.rpm

    Verified the java version:

    # java -version
    java version "1.7.0_65"
    Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
    

    Check in above output that it says "HotSpot"....

    Once this is done, then I installed tomcat (http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz) from the source.

    BTW, I always use netstat -anp | grep 8080 instead of user -v -n tcp 8080.

    The bottom line is, I resolved this issue by removing OpenJDK and installing Oracle JDK. That's the essence.

    In case you need steps on installing tomcat from source, then let me know.

    EDIT: As requested, Here are the steps to install Tomcat from source:

    Download Tomcat and move it to /usr/share/:

    # wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz
    # tar -xvzf apache-tomcat-7.0.55.tar.gz
    # mv apache-tomcat-7.0.55 /usr/share/
    

    Create /etc/init.d/tomcat script as below:

    #!/bin/bash
    # description: Tomcat Start Stop Restart
    # processname: tomcat
    # chkconfig: 234 20 80
    JAVA_HOME=/usr/java/default/
    export JAVA_HOME
    PATH=$JAVA_HOME/bin:$PATH
    export PATH
    CATALINA_HOME=/usr/share/apache-tomcat-7.0.55
    
    case $1 in
    start)
    sh $CATALINA_HOME/bin/startup.sh
    ;;
    stop)
    sh $CATALINA_HOME/bin/shutdown.sh
    ;;
    restart)
    sh $CATALINA_HOME/bin/shutdown.sh
    sh $CATALINA_HOME/bin/startup.sh
    ;;
    esac
    exit 0
    

    Run below commands (these should be self-explanatory):

    # chmod 755 /etc/init.d/tomcat
    # chkconfig  --add tomcat
    # chkconfig  tomcat on
    # chkconfig  --list tomcat
    

    I usually stop iptables for the time being to avoid unnecessary trouble:

    # service iptables stop
    

    Start the Tomcat:

    # service tomcat start
    

    Ensure that tomcat is running:

    # netstat -anp | grep 8080
    tcp        0      0 :::8080                     :::*                        LISTEN      1704/java
    

    That's it !!

    There are various methods to install tomcat. I always follow this method for installing and running tomcat as a service.