Java Web Application


JDK and Apache Maven

On Ubuntu 18.04, you can install maven and you will also get OpenJDK.

sudo apt-get update && sudo apt-get install maven -y

After installation is completed, check versions:

$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

$ mvn --version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-17763-microsoft", arch: "amd64", family: "unix"

Or you can manually install from:

Configure JAVA_HOME

Find JDK home directory

$ java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
    java.home = /usr/lib/jvm/java-11-openjdk-amd64

Edit ~/.bashrc and append these lines:



Tomcat is required to run your WAR file. Download Apache Tomcat 8.5 from

Extract files and append the following lines to ~/.bashrc.


Configure Tomcat

Insert the following lines between <tomcat-users></tomcat-users> block

  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="password" roles="manager-gui, manager-script"/>

Start and Stop Tomcat

Start Tomcat

Visit http://localhost:8080 to check server is up

Stop Tomcat

Initializing Project

Generate the project

mvn archetype:generate "-DgroupId=sh.par" "-DartifactId=helloworld" "-DarchetypeArtifactId=maven-archetype-webapp" "-Dversion=1.0-SNAPSHOT"

Build and package

mvn package

The WAR file in target folder.

Deploy to Tomcat

Start the server and go to web GUI at http://localhost:8080/ 

Click Manager App button


Input configured username and password.

Select the WAR file and click Deploy button


Your deployed application should appear on the list.


You can click Undeploy button to remove your application.