Setting Up Java Web Environment on Ubuntu
Running a Java Web Archive (.war) file on Ubuntu requires a servlet container like Apache Tomcat. This guide explains the complete deployment process.
Java Installation
Java is essential for executing .war files as they are Java-based web applications.
Verify Java Installation
Check if Java is already installed:
java -version
If Java is not present, install OpenJDK:
sudo apt update
sudo apt install openjdk-17-jdk -y
Confirm successful installation:
java -version
Tomcat Server Setup
A Java servlet container is required to host web applications. Apache Tomcat is a popular choice.
Download and Install Tomcat
Download the Tomcat binary package to the /opt directory:
Extract the archive:
sudo tar -xvzf apache-tomcat-10.1.8.tar.gz sudo mv apache-tomcat-10.1.8 java-web-serverTomcat Configuration and Startup
Grant Execution Permissions
Make Tomcat scripts executable:
cd /opt/java-web-server sudo chmod +x bin/*.shStart Tomcat Service
Launch the Tomcat server:
sudo ./bin/startup.shSuccessful startup will display:
Using CATALINA_BASE: /opt/java-web-server Using CATALINA_HOME: /opt/java-web-server Using CATALINA_TMPDIR: /opt/java-web-server/temp Using JRE_HOME: /usr/lib/jvm/java-17-openjdk-amd64 Using CLASSPATH: /opt/java-web-server/bin/bootstrap.jar:/opt/java-web-server/bin/tomcat-juli.jar Server startup in 1234 msAccess Tomcat Welcome Page
Open a web browser and navigate to
http://your-server-ip:8080. You should see the Tomcat welcome page.Deploying Web Applications
There are two primary methods to deploy .war files:
Method 1: Direct Deployment to webapps Directory
Copy your .war file to the webapps directory:
sudo cp /path/to/your-webapp.war /opt/java-web-server/webapps/Tomcat will automatically detect and deploy the application. Access it at
http://your-server-ip:8080/your-webapp.Method 2: Using Tomcat Manager
If Tomcat Manager is configured, visit
http://your-server-ip:8080/manager/textand deploy via the web interface.Troubleshooting
Monitor Tomcat logs for issues:
sudo tail -f /opt/java-web-server/logs/catalina.outThis log displays deployment status and error information for your web applications.
Managing Tomcat Service
To stop Tomcat:
sudo ./bin/shutdown.shTo restart Tomcat:
sudo ./bin/shutdown.sh sudo ./bin/startup.sh