Automate SpringBoot Deployment on Windows with Jenkins and WinSW
This guide explains how to set up Jenkins and WinSW on a Windows 10 server to automatically build, package, and deploy a SpringBoot application using batch scripts, covering environment preparation, configuration files, and Jenkins pipeline steps for streamlined backend deployment.
Introduction
When developing Java backend applications on a Windows 10 server, manually uploading and running scripts for updates can waste time and increase management complexity. This article records a fast update workflow that combines Jenkins, WinSW, and Git to automate SpringBoot project deployment.
What is Jenkins?
Jenkins is an open‑source automation server (formerly Hudson) that simplifies continuous integration (CI) and continuous delivery (CD) through pipelines and plugins. It runs on Windows, macOS, and Linux and can be extended to fit virtually any development process.
Environment Preparation
Jenkins
Download the Jenkins .war package (prefer the WAR distribution). The latest Jenkins version requires JDK 17 or JDK 21. If you need to use an older JDK (e.g., JDK 8), install multiple JDKs in separate directories and launch Jenkins by specifying the full path, for example:
E:\jdk21\bin>java -jar -Dfile.encoding=UTF-8 C:\Users\Administrator\Desktop\jar包\jenkins.war --prefix=/vjenkins/On first launch Jenkins displays an initial admin password that must be entered to set up a login.
WinSW
Download the appropriate WinSW binary and the sample-minimal.xml configuration file from GitHub:
https://github.com/winsw/winsw/releases/download/v2.12.0/sample-minimal.xmlPlace the XML file in the SpringBoot project root, rename the WinSW executable (e.g., test.exe), and rename the XML to match (e.g., test.xml). Edit test.xml as follows:
<service>
<id>test</id>
<name>test</name>
<executable>java</executable>
<!-- Specify the absolute JAR path -->
<arguments>-jar "./target/test-1.0-SNAPSHOT.jar" --server.port=8187</arguments>
<!-- Log directory configuration -->
<logpath>./logs</logpath>
<description>This is a test service</description>
</service>Key parameters:
id – service identifier
name – service name
executable – command to run (java for JAR files)
arguments – command‑line arguments
logpath – location of log files
description – brief service description
Batch Startup Script
Create run.bat in the project root to stop the existing service, rebuild the JAR with Maven, reinstall the service, and start it. Example script:
@echo off
setlocal enabledelayedexpansion
:: Configuration parameters
set SERVICE_NAME=test
set WINSW_EXE=test.exe
set MAVEN_HOME=E:\maven\apache-maven-3.8.9
set LOG_FILE=deploy_log.log
:: Record start time
echo [%time%] Deployment process started >> %LOG_FILE%
:: Stop existing service
echo [%time%] Stopping the service... >> %LOG_FILE%
net stop %SERVICE_NAME% 2>nul
if %errorlevel% equ 0 (
echo [%time%] Service stopped successfully >> %LOG_FILE%
) else (
echo [%time%] Service not running or failed to stop >> %LOG_FILE%
)
:: Uninstall old service
echo [%time%] Uninstalling old service... >> %LOG_FILE%
%WINSW_EXE% uninstall
if %errorlevel% neq 0 (
echo [%time%] Warning: Failed to uninstall old service (possibly not installed) >> %LOG_FILE%
)
:: Maven package
echo [%time%] Executing Maven package... >> %LOG_FILE%
call %MAVEN_HOME%\bin\mvn clean package
if %errorlevel% neq 0 (
echo [%time%] Error: Maven package failed! >> %LOG_FILE%
exit /b 1
)
echo [%time%] Maven package successful >> %LOG_FILE%
:: Install new service
echo [%time%] Installing new service... >> %LOG_FILE%
%WINSW_EXE% install
if %errorlevel% neq 0 (
echo [%time%] Error: Service installation failed! >> %LOG_FILE%
exit /b 1
)
echo [%time%] Service installed successfully >> %LOG_FILE%
:: Start service
echo [%time%] Starting the service... >> %LOG_FILE%
net start %SERVICE_NAME%
if %errorlevel% neq 0 (
echo [%time%] Error: Service failed to start! >> %LOG_FILE%
exit /b 1
)
echo [%time%] Service started successfully >> %LOG_FILE%
:: Completion
echo [%time%] Deployment process completed >> %LOG_FILE%
exit /b 0Adjust the paths and variables to match your environment.
Jenkins Configuration Steps
1. Log into Jenkins and create a new Freestyle Project (see screenshot).
2. In the project configuration, under Source Code Management , set the Git repository URL (add credentials for private repos) and specify the branch to deploy.
3. In Build Steps , add an Execute Windows batch command step that runs the run.bat script:
@echo off
setlocal enabledelayedexpansion
./run.bat
exit /b 0Save the configuration. Clicking Build triggers Jenkins to pull the code, execute the batch script, and deploy the SpringBoot service automatically.
After setup, developers only need to push changes to Git; Jenkins handles packaging and service restart, greatly simplifying backend deployment. IDE plugins (e.g., Jenkins plugin for IntelliJ IDEA) can further streamline remote builds.
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.
Dunmao Tech Hub
Sharing selected technical articles synced from CSDN. Follow us on CSDN: Dunmao.
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.
