Report 4 - Deploying Spring application with TomCat

Feb. 24, 2020

Posted in:

This is my report on the fourth exercise on my schools Linux server course

(This webapp is currently running on http://138.68.81.177:8084/, you can register to the application from http://138.68.81.177:8084/register)

For this week's exercise we had to either do a couple of exercises that dealt with setting up a public server with a cloud computing platform such as AWS or Digital Ocean and deploy a website there.

We had also alternate exercise which we could do instead which I did.

I had to code a webservice, which could basically be anything. I had old project laying around which was this filestorage (cloud storage) web application. I did some improvements to this particular project and fixed up the whole thing and deployed it.

Deploying a Java Spring project to Digital Ocean is fairly straightforward.

This time around I had to use TomCat as the server on my Ubuntu droplet.

This article had all the steps needed for this part of the installation: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04

One reason I love digital ocean so much, is the documentation they have available on deploying application on almost any technology. If one does not exists, then someone has atleast made a post on the digital ocean forum about the particular issue I might be facing when it comes to deploying something to the cloud platform.

On my local machine I first had to build the Java Spring project with mvn clean install command on the root folder, which creates an executable .jar file.

Steps in order

sudo apt-get update - To update the apt list

sudo apt-get install default-jdk - Basically installs java on the server

After getting the java installed I had to install tomcat.

First I went to the /tmp/ folder which is basically a folder you can use for temporary files you don't need later such as installation files or zip files.

On the tmp folder I ran the command:

wget http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz

After this file is downloaded then I had to unzip the file with the following command:

sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

Here I ran into the following error:

Screenshot 2020-02-26 at 1.30.43.png

After some troubleshooting and googling around for answer I used cat command for the gzip file and it basically showed an blank html file:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>404 Not Found</title>

</head><body>

<h1>Not Found</h1>

<p>The requested URL was not found on this server.</p>

<hr>

<address>Apache Server at apache.mirrors.ionfish.org Port 80</address>

</body></html>

So this means that for some reason the file no longer exists on Apache's end and digital ocens documentation was maybe little bit old. I had to manually go to the http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.9/bin/ -website and search for the newest 8.* tomcat file there which I found and managed to downloada the proper file with

wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.9/bin/apache-tomcat-8.5.9.tar.gz

After this I managed to unzip the file to the /opt/ -folder with the following commnd:

tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

After this particular bumb on the road it was smooth sailing with setting up tomcat and I basically followed the documentation I linked earlier in this post.

After tomcat is setup on the linux server, this is the admin/management panel of the server located on the address: http://138.68.81.177:8080/manager/html

Screenshot 2020-02-26 at 3.27.23.png

From the picture you can also see there is an easy option to deploy an war file (I built mine on the local machine with the mvn clean package command).

My knowledge of the war files is currently littlebit shaky and in all honesty it took about 20 redeployments to get this website deployed live. I kept running into 404 -error when trying to access my website. This part of the deployment probably ate 3 hours in total-

In the end I had to unpack the war file and run the Spring main class manually from the /opt/tomcat/WEB-INF -folder with command java -classpath "lib/*:classes/." com.mikkoharakka.fakebox.FakeBox. I also had to modify the application.properties -file on production with Vim to change the port to 8084, because the port 8080 was obviously in use by TomCat. This particular web application as it's currently deployed is on pretty shaky grounds and there was simply so much of new information and different technologies that the task seemed impossible at some point. I've also never deployed Java application to an external server before and I have to sy the easy of deployment on other technologies such as Python or React JS seem to be way simpler.

Return to blog