Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Automated Deployment of a Standalone Java Web Application on Linux

Tech May 9 3

Prepare Required Files

Use an SSH client like MobaXterm to connect to the remote Linux server and transfer the necessary packages: JDK, Apache Tomcat, MySQL, and optionally Nginx. Once uploaded, extract all archives in advance to streamline setup.

# Extract JDK
tar -zxvf jdk-8u151-linux-x64.tar.gz

# Extract Tomcat
tar -zxvf apache-tomcat-8.5.20.tar.gz

# Extract MySQL RPM bundle (preferably into its own directory)
tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar

Install and Configure JDK

Edit the global profile to set environment variables:

sudo vi /etc/profile

Append the following lines (adjust the path to match your extracted JDK location):

# Java environment
export JAVA_HOME=/opt/jdk1.8.0_151
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH

Reload the profile and verify the installation:

source /etc/profile
java -version

Configure Tomcat for Auto-Start

Copy Tomcat’s startup script to the system’s init directory and rename it:

cp /opt/apache-tomcat-8.5.20/bin/catalina.sh /etc/init.d/tomcat

Edit /etc/init.d/tomcat and insert the following just after the initial comments:

# chkconfig: 2345 80 20
# description: Tomcat Server

JAVA_HOME=/opt/jdk1.8.0_151
CATALINA_HOME=/opt/apache-tomcat-8.5.20

Make the script executable and register it with the system:

chmod +x /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on

Open port 8080 in the firewall if needed:

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

Install and Enable MySQL

First, remove any existing MariaDB packages:

rpm -qa | grep mariadb
sudo rpm -e --nodeps <mariadb-package-name>

Install the required MySQL RPMs from the extracted bundle:

cd mysql-extracted-dir
sudo rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm

Start and enable MySQL at boot:

systemctl start mysqld
systemctl enable mysqld

Retrieve the temporary root password:

grep 'temporary password' /var/log/mysqld.log

Log in and update the root password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';

Grant remote access if needed (optional):

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NewStrongPassword123!' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Final, import your application’s SQL schema:

mysql -u root -p < /path/to/your-schema.sql

Deploy the Application

Place your WAR file into Tomcat’s webapps directory:

cp myapp.war /opt/apache-tomcat-8.5.20/webapps/

Restart Tomcat to deploy:

service tomcat restart

The application should now be accessible at http://<server-ip>:8080/myapp.

Tags: Linuxtomcat

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.