In this tutorial, we will show you how to install Jetty 9 on a Linux VPS running Ubuntu 18.04.
Jetty is an open-source HTTP Servlet Server written entirely in Java. It is designed to be lightweight, high-performance, embeddable, extensible, and flexible, thus making it an ideal platform for serving dynamic HTTP requests from any Java application. Let’s begin with the installation.
Table of Contents
Prerequisites:
Make sure that your server meets the following minimum requirements:
- For the purposes of this tutorial, we will use an Ubuntu VPS (preferably a fresh installation of Ubuntu 18.04 LTS).
- Full SSH root access or a user with sudo privileges is also required.
- Java 8 or higher.
Step 1: Connect to the Server
To connect to your server via SSH as the root user, use the following command:
ssh root@IP_ADDRESS -p PORT_NUMBER
and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.
Once logged in, let’s make sure that your Ubuntu 18.04 server is up-to-date by running the following commands:
$ apt-get update $ apt-get upgrade
This helps maximize compatibility and security between packages and ensures that the install process will go smoothly.
Step 2: Install Java on Ubuntu 18.04
Jetty 9 depends on the Java Development Kit (JDK). We can check if Java is already installed using this command:
which java
If there is no output, it means that Java is not installed on the server yet.
You can install Oracle JDK or OpenJDK depending on your choice. We’ll use OpenJDK, as that’s what is readily available in the pre-installed Ubuntu package repositories. They are functionally identical, so choosing either one will not affect how the program runs. We also included the Oracle JDK install further down below if necessary.
You can install OpenJDK with the following command:
$ sudo apt install openjdk-8-jdk
To check if everything is set correctly, run this next line:
$ java -version
After which you should see something like the following:
openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03) OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
If however, you have a specific reason to use the Oracle JDK, this command will install Oracle JDK 8 using the PPA repository:
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer
Step 3: Install Jetty 9
Jetty 9 is available in the pre-installed Ubuntu package repositories. You can install it with the following command:
$ sudo apt install jetty9
Once the installation is complete, Jetty 9 will be automatically started.
To check and verify the installed Jetty version, run the following command:
$ apt show jetty
At which point you should see something like the following. You might have a later version than the one shown here:
Package: jetty9 Version: 9.4.15-1~18.04.1ubuntu1 Priority: optional Section: universe/java Origin: Ubuntu
Step 4: Managing the Jetty 9 Service
Enable the Jetty 9 at boot time using the following command:
$ sudo systemctl enable jetty9
Start Jetty 9 service using this command:
$ sudo systemctl start jetty9
We can restart Jetty 9 using:
$ sudo systemctl restart jetty9
In order to stop Jetty 9, we can use this command:
$ sudo systemctl stop jetty9
We can check the service status using:
$ systemctl status jetty9
The output of this command should be similar to this:
● jetty9.service - Jetty 9 Web Application Server Loaded: loaded (/lib/systemd/system/jetty9.service; enabled; vendor preset: enabled) Active: active (running) Docs: https://www.eclipse.org/jetty/documentation/current/ Main PID: 19382 (java) Tasks: 24 (limit: 2321) CGroup: /system.slice/jetty9.service └─19382 /usr/bin/java -Djetty.home=/usr/share/jetty9 -Djetty.base=/usr/share/jetty9 -Djava.io.tmpdir=/tmp -jar /usr/share/jetty9/start.jar jetty.state=/var/lib/jetty9/jetty.state jetty-started.xml
Step 5: Accessing the Jetty Installation
Jetty runs on port 8080. To access your Jetty installation, you will need to type the following URL in your web browser. Replace ‘your-ip-addess‘ with your server’s public IP address:
http://your-ip-address:8080/
Step 6: Create a Reverse Proxy in Apache
We can also configure the Apache2 web server as a reverse proxy for the Jetty 9 web server. This means that Apache will accept all requests through port 80 in front of Jetty 9, which is running on port 8080. In order to do this, we’ll need to enable two Apache modules: proxy and proxy_http. We can use the ‘a2enmod’ command to enable them:
$ sudo a2enmod proxy $ sudo a2enmod proxy_http
After we install these modules, we have to restart Apache for the changes to take effect:
$ sudo systemctl restart apache2
Create/modify the virtual host configuration about your domain and add/modify the proxy directives (ProxyRequests, ProxyPass and ProxyPassReverse) as shown in our example:
$ sudo nano /etc/apache2/sites-available/your_domain.com.conf
Copy and paste the content below in the Apache configuration file and save it. Don’t forget to replace “your_domain.com” with your own domain name. NOTE: This tutorial assumes that you already have a registered domain name that’s already configured to point towards your server’s IP address. Enter the following data:
<VirtualHost *:80> ServerName your_domain.com ServerAlias www.your_domain.com ProxyRequests off ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ </VirtualHost>
Enable the ‘your-domain.com.conf’ Apache configuration file if it was not previously enabled, and restart Apache for the changes to take effect:
$ sudo a2ensite your_domain.com.conf
$ sudo systemctl restart apache2
Now we can access the Jetty 9 webapp without needing to specify port 8080 in a web browser, meaning that we can now access it using: http://your-domain.com
.
That’s all there is to it. We have successfully installed Jetty 9 on Ubuntu 18.04. Now you can use Jetty to run all sorts of Java applications easily.
Of course, you don’t have to install and configure Jetty 9 on Ubuntu 18.04 if you use one of our Managed Jetty Hosting solutions, in which case you can simply ask our expert Linux admins to set up and configure Jetty 9 on Ubuntu 18.04 for you. They are available 24×7 and will take care of your request immediately.
PS. If you found our tutorial on how to install Jetty on Ubuntu 18.04 helpful, please share it with your friends on the social networks using the share shortcuts below, or just leave a comment down in the comments section. Thank you.
Thanks. How am I just learning about Reverse Proxy after all these years. Great tutorial.