Automated Deployment of a Standalone Java Web Application on Linux
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.