Master Java Spring Boot Deployment with Jenkins: From Maven Build to Automated CI/CD
This guide walks you through the fundamentals of Java Spring Boot projects, explains WAR vs JAR deployment, sets up Maven and Jenkins, configures SSH and DingTalk notifications, and provides a complete CI/CD pipeline with scripts for automated builds and releases.
What Is a Java Project (Spring Boot)
A Java backend project is developed in the Java language and must be compiled before it can run. Compared with PHP (WordPress) or Python (JumpServer), a Java project requires a Java development environment, compilation, and packaging into a JAR file that can be executed by a Java process. Spring Boot is a popular Java framework for building web back‑end services.
1.1 Java Project Deployment Methods
There are two common ways to deploy Java web applications:
WAR package : The build delivers a *.war zip containing HTML, configuration files, and compiled Java code. Operations only need to provide an application container such as Tomcat to host the WAR.
JAR package (Spring Boot) : The build delivers a *.jar zip that already embeds Tomcat. Operations can simply run java -jar app.jar without installing a separate container.
1.2 WAR vs JAR Differences
With a WAR, the ops team must install Tomcat, place the WAR in webapps, and Tomcat will unpack it automatically. With a JAR, the ops team runs java -jar app.jar directly. Building a JAR requires Maven: mvn clean install After the build, the JAR appears in target/. Example repository:
git clone https://gitee.com/yuco/springboot-test.git2. Project Architecture
The architecture follows these steps:
Developers push code to GitLab, which triggers a Jenkins job for automatic builds.
Jenkins packages the Java project, uploads the artifact via SSH, and restarts the service, notifying a DingTalk group.
3. Build Server Environment Checks
3.1 Java Environment
# java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64‑Bit Server VM (build 25.332-b09, mixed mode)3.2 Maven Environment
Maven manages dependencies, standard project structure, and the build lifecycle (compile, test, package, deploy). A typical Maven project layout is:
a-maven-project
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
└── target3.3 Installing JDK and Maven
Install JDK 1.8 and Maven 3.3.9, configure /etc/profile to add Maven to PATH, and verify with mvn -v. Use a Chinese mirror (e.g., Tsinghua) in settings.xml to speed up dependency download.
3.4 Jenkins Plugin Check
Ensure the following plugins are installed in Jenkins:
Git plugin
Maven Integration plugin
Publish Over SSH
DingTalk plugin
3.5 Configure SSH in Jenkins
Set up password‑less SSH between the Jenkins server and target machines. Example command to copy the public key to multiple hosts:
for i in 7 8; do ssh-copy-id [email protected].$i; doneJenkins SSH configuration requires the private key, host, username, remote directory, and command to execute.
4. Create Jenkins Job
4.1 New Job
Create a Maven project job in Jenkins and give it a meaningful name.
4.2 Discard Old Builds
Enable the option to discard old builds to save space.
4.3 Git Source Management
Link the job to a GitLab repository that contains the Spring Boot source code.
4.4 Webhook Trigger
Configure a GitLab webhook so that a push event triggers the Jenkins job, e.g.:
http://10.0.0.100:8080/project/springboot-yuchao4.5 Build Environment
In the Build step, run Maven with the following command to skip tests:
mvn clean install -Dmaven.test.skip=true4.5.1 Maven Packaging Output
[INFO] Building jar: /tmp/chapter1/target/www.yuchaoit.cn-0.0.1.jar
[INFO] BUILD SUCCESS
[INFO] Total time: 2.412 s4.6 Deploy Script Development
Create a deployment script on the target machines (e.g., /root/jenkins-sh/deploy.sh) that kills the old Java process, backs up the previous JAR, copies the new JAR, and starts it with JVM options and JMX enabled.
#!/bin/bash
DATE=$(date +%Y%m%d)
DIR=/usr/local/app
JARFILE=www.yuchaoit.cn-0.0.1.jar
if [ ! -d $DIR/backup ]; then mkdir -p $DIR/backup; fi
cd $DIR
ps -ef | grep $JARFILE | grep -v grep | awk '{print $2}' | xargs -r kill -9
mv $JARFILE $DIR/backup/$JARFILE$DATE
mv -f /root/jenkins-sh/target/$JARFILE .
java -server -Xms1024M -Xmx1024M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -Xloggc:./gc.log -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dserver.address=0.0.0.0 -Dserver.port=18888 -jar $JARFILE --spring.profiles.active=dev > /nohup 2>&1 &
if [ $? = 0 ]; then sleep 30; tail -n 50 out.log; fi
cd backup/
ls -lt | awk 'NR>5{print $NF}' | xargs rm -rf
echo "starting success!!!"Make the script executable with chmod +x deploy.sh.
4.7 Build and Test
Click “Build Now” in Jenkins, verify that the job runs, and check that the DingTalk notification is received.
4.8 DingTalk Notification
Configure the DingTalk plugin with the appropriate IP whitelist and webhook token so that build results are pushed to a DingTalk group.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
