Automating Java Project Build, Packaging, and Deployment with Jenkins
This guide explains how to configure Jenkins to pull Java code from Git, compile and package it with Maven, transfer the artifact to a test server via SCP, and restart Tomcat, providing a complete CI/CD pipeline for Java applications.
Jenkins can automate the update, build, and deployment processes for Java projects, which typically use Maven for compilation and packaging, so Maven must be installed in the Jenkins environment.
Jenkins deployment of a Java project includes:
Pulling Git code;
Compiling and packaging the project with Maven;
Copying the packaged artifact to a designated test server via SCP;
Restarting Tomcat on the test server.
Step 1 – Retrieve Git code: Install the Git Parameter plugin in Jenkins (System → Manage Plugins → search and install). In a new job, configure the Source Code Management section with the Git repository URL and credentials. Set the Branch Specifier to $Branch to fetch all branches.
Step 2 – Automatic build: Use a shell build step to run Maven commands. First, change to the cloned directory, then execute: mvn -s /path/to/settings.xml clean install If only one Maven installation exists on the server, the -s option can be omitted; otherwise, specify the absolute path to the desired settings.xml. Ensure all dependent packages are available before building.
Step 3 – Upload packaged file to the test server: Configure password‑less SSH between the Jenkins server and the Java project server, then use scp to copy the Maven‑generated artifact to the test server. It is recommended to back up the existing package before overwriting.
Step 4 – Delete old PID and restart Tomcat: Use a shell command on the test server to stop Tomcat, remove the old PID, and start Tomcat again (e.g., run the provided restart script).
After completing these configurations, the Jenkins job will display all Git branches in the "Build with Parameters" screen; select the desired branch, start the build, and monitor the console output for progress and results.
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.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
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.
