Search code examples
javaubuntutomcatubuntu-14.04geoserver

Error installing GeoServer - HTTP Status 404 - /geoserver and Application at context path /geoserver could not be started


I've recently tried to install GeoServer with Tomcat7 on a Lubuntu 14.04 server, and had a lot of problems doing so, because Tomcat7's Java default version was set to 1.7. I've struggled a lot with this last night and I'd like to document how to fix it.


I installed GeoServer in my Lubuntu 14.04 machine following these steps:

1) Install Java 8, as documented here

sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

After that, running java -versionreturned:

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

2) Install Tomcat 7

sudo apt-get install tomcat7 tomcat7-admin

3) Install GeoServer's "Web Archive" version

cd ~/Downloads
wget http://sourceforge.net/projects/geoserver/files/GeoServer/2.11.0/geoserver-2.11.0-war.zip
unzip geoserver-2.11.0-war.zip geoserver.war
sudo mv geoserver.war /var/lib/tomcat7/webapps/
sudo service tomcat7 restart

After that, I could not access localhost:8080/geoserver. Trying to do so returned the HTTP Status 404 - /geoserver error, with "The requested resource is not available." as a description.

Trying to deploy the .war file through Tomcat's /manager page also did not work, returning the following error: Application at context path /geoserver could not be started.

I've looked in the error logs to see what was going wrong, and found the following exception:

Apr 29, 2017 12:32:49 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.geoserver.platform.GeoServerHttpSessionListenerProxy
java.lang.UnsupportedClassVersionError: org/geoserver/platform/GeoServerHttpSessionListenerProxy : Unsupported major.minor version 52.0 (unable to load class org.geoserver.platform.GeoServerHttpSessionListenerProxy)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2970)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1209)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1689)
        [...]

Despite what the error message says, echoing $JAVA_HOME returned /usr/lib/jvm/java-8-oracle, so I was sure I had the necessary Java version.


Solution

  • Apparently Tomcat 7 ships with 1.7 JVM as the default. This can be checked on Tomcat Web Application Manager (usually at localhost:8080/manager), at the bottom of the page there is a table with the JVM version.

    +-------------------------------+---------------+-------+
    |        Tomcat Version         |  JVM Version  | [...] |
    +-------------------------------+---------------+-------+
    | Apache Tomcat/7.0.52 (Ubuntu) | 1.7.0_121-b00 | [...] |
    +-------------------------------+---------------+-------+
    

    Since GeoServer requires Java 1.8, this explains the UnsupportedClassVersionError. We must explicitly tell Tomcat to use JVM 1.8. This was documented here and the steps are the following:

    First of all we need to find where JVM 1.8 is located. Open a console terminal and enter:

    $ echo $JAVA_HOME
    

    The path to Java 8's folder should be echoed back to you. In my case it's /usr/lib/jvm/java-8-oracle. Make sure to copy it.

    Then we have to edit Tomcat's configurations and tell it to use this JVM. On the console terminal, type in:

    $ sudo nano /etc/default/tomcat7
    

    The configuration file for Tomcat 7 should be opened. Locate the following text in it:

    # The home directory of the Java development kit (JDK). You need at least
    # JDK version 1.5. If JAVA_HOME is not set, some common directories for
    # OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
    #JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
    

    Find the line that starts with JAVA_HOME, and change the path to your Java 8 folder. Make sure to uncomment the line by removing the # before JAVA_HOME. In my case, the file ended up like this:

    # The home directory of the Java development kit (JDK). You need at least
    # JDK version 1.5. If JAVA_HOME is not set, some common directories for
    # OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
    JAVA_HOME=/usr/lib/jvm/java-8-oracle
    

    After that we need to restart Tomcat with the following command:

    $ sudo service tomcat7 restart
    

    Then if we check localhost:8080/manager, in the bottom of the page there should be something like:

    +-------------------------------+---------------+-------+
    |        Tomcat Version         |  JVM Version  | [...] |
    +-------------------------------+---------------+-------+
    | Apache Tomcat/7.0.52 (Ubuntu) | 1.8.0_131-b11 | [...] |
    +-------------------------------+---------------+-------+
    

    And GeoServer should now be successfully started, and it should be accessible through localhost:8080/geoserver.