7 min read

(For more resources related to this topic, see here.)

Installing Java

GeoServer is a Java application. So, we need to ensure that you have it installed and properly working on your machine, but you don’t need to know how to write Java™ to install or to get started using GeoServer.

There are two main packages of Java. Depending on what you are planning to do with Java, you may want to install a JDK (Java Development Kit) or JRE (Java Runtime Environment). The former enables you to compile Java™ code, while the latter has all you need to run most Java applications.

Starting from release 2.0, GeoServer does not need a full JDK installation and you can go safely with JRE. It works well with Java 6 but as Java 7 is not deeply tested by developers, it should work but you may experience minor issues. Unless you have some strong reasons to use Java 7, you should use JRE 6.

In the 90s, Java development was started by Sun Microsystems. Sun has developed each new release until it merged into Oracle Corporation. While Oracle did not change the Java license to a commercial one, there are some license issues (maybe it would be worthy to add some reference here) preventing Oracle Java™ from being available on an Ubuntu repository.

On Ubuntu current releases, you will find OpenJDK already installed in the desktop edition; in the server, you need to choose it at setup. While there are a few users running GeoServer on OpenJDK with no issues, the developers community does not test it intensively and hence you can expect some performance loss.

Oracle Java™ should be your first choice unless you have some specific issues. In the following steps, we will use Oracle Java™ JRE. If your installation machine is a new one, then chances are that there is no Java runtime pre-installed. Let’s check.

Time for action — checking the presence of Java on Windows

We will verify the presence of a JRE/JDK installation on Windows, using the following steps:

  1. From the Start menu, select Control Panel.

  2. Then select Programs. If your system has a JRE/JDK installed, you should see an icon with the Java logo as shown in the following screenshot. It is a shortcut to the Java control panel.

  3. Open the Java control panel and select the Java tab. Here you will find settings for JRE. Press the Show Me button to visualize the installed release and the installation folder.

What just happened?

You checked for the presence of Java on your computer. In case you didn’t find it, we are going to install it in the next section. (If you did find it, skip to the Installing Apache Tomcat section.)

Time for action — checking the presence of Java on Ubuntu

We will check JRE/JDK installation from the command line.

  1. Log in to your server and run this command:

    ~ $ sudo update-alternatives --config java

  2. If there is no Java properly configured you should see an output like the following:

    update-alternatives: error: no alternatives for java.

  3. In case there is one or more Java installed the output will be similar to:

    There is only one alternative in link group java: /usr/lib/jvm/ java-7-openjdk-amd64/jre/bin/java Nothing to configure.

    Or

    There are 2 choices for the alternative java (providing /usr/bin/ java). Selection Path Priority Status ———————————————————— * 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode 1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode Press enter to keep the current choice[*], or type selection number:

What just happened?

requirement for our installation. We had the opportunity to check if the installed release, in case we found it, is suitable for running GeoServer.

Now we will go through the installation of JRE.

Time for action — installing JRE on Windows

We will install Oracle JRE 1.6. We are assuming that you didn’t find any previous Java installation.

  1. Navigate to the Downloads tab at http://www.oracle.com/technetwork/java/javase/downloads/jre6u37-downloads-1859589.html.

  2. Select the installer for Windows 64-bit, that is, jre-6u37-windows-x64.exe, and save it in a convenient folder.

  3. Select the downloaded file and run it as an administrator; press the Yes button when asked from the User Account control.

  4. Go with the default settings and press the Install button.
  5. After it has been downloaded, you should see a window informing you about the success of installation.

What just happened?

We installed JRE on your Windows computer. The first requirement is now fulfilled and you can go over to the Tomcat installation.

Time for action — installing JRE on Ubuntu

We will install Oracle JRE 1.6. As mentioned previously, there is no Ubuntu package for Java 6; we are going to perform a manual installation.

  1. Visit the download area at http://www.oracle.com/technetwork/java/javase/downloads/jre6u37-downloads-1859589.html.

  2. Download the tar.gz archive, choosing the 32-bit or 64-bit archive, depending on the Ubuntu edition you are working with. You must accept the license agreement (reading it might be a nice idea) before you can select one of the tar.gz archives (be sure to avoid rpm archives as they are not for Debian-based Linux distribution).

  3. Save the archive to your home folder and extract it.

    ~ $ chmod a+x jre-6u37-linux-x64.bin ~ $ ./jre-6u37-linux-x64.bin

  4. The JRE 6 package is extracted into ./jre1.6.0_37 folder. Now move the JRE 6 directory to /opt and create a symbolic link to it in the default folder for libraries.

    ~ $ sudo mv ./jre1.6.0_37* /opt ~ $ sudo ln -s /opt/jre1.6.0_37 /usr/lib/jvm/

  5. Let’s check the installation:

    ~ $ /opt/jre1.6.0_37/bin/java -version java version "1.6.0_37" Java(TM) SE Runtime Environment (build 1.6.0_37-b06) Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode)

  6. Although not strictly requested by the GeoServer installation, it is worth configuring the JRE as the primary Java alternative in your system:

    ~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/ jvm/jre1.6.0_37/bin/java 0

  7. Now you need to configure the Oracle JRE as default:

    ~ $ sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/ java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/jre1.6.0_37/bin/java 0 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/jre1.6.0_37/bin/java to provide /usr/bin/java (java) in manual mode.

  8. Clean your box by deleting the archive:

    ~$ rm jre-6u37-linux-x64.bin

What just happened?

We installed JRE. Now we can run a Java application on the JVM contained in the JRE. The JVM supports several different kinds of Java application; for example, a console-only application, an applet running in a browser, or a full desktop application. For GeoServer (a web application), we need another component on top of the JVM, that is, a servlet container.

Installing Apache Tomcat

Having correctly installed the JRE you can now pass on and install the servlet container. Servlet container, or web container, is the component server that interacts with the servlets. It is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet, and ensuring access security. It should implement Java servlet and JavaServer Pages technologies.

As for JRE, you have a few choices here; a brief list is at http://en.wikipedia.org/wiki/Web_container.

Apache Tomcat, GlassFish, and JBoss are most popular and are all available in an open source edition. You may wonder which one is the best choice for running GeoServer. In a production environment, usually the same container is shared among several web applications. You are not going to choose the container; the architects and system administrators made their choices and you have to conform to them. As a beginner, you have the opportunity of selecting it! Apache Tomcat should be your first choice as it is widely adopted in the Geoserver developer’s community. If you run into any issues, the answer is probably waiting for you in the mailing list archive.

We are going to install Apache Tomcat. It is an open source project of Apache foundation (http://tomcat.apache.org) and there are reasons for installing it such as it is widely used, well-documented, and relatively simple to configure.

So let’s start the Apache Tomcat installation.

LEAVE A REPLY

Please enter your comment!
Please enter your name here