Skip to main content

Command Palette

Search for a command to run...

How to run spring boot app as windows service (winsw)

Updated
2 min read
S

👋 Hey there! I’m Shohanur Rahman!

I’m a backend developer with over 5.5 years of experience in building scalable and efficient web applications. My work focuses on Java, Spring Boot, and microservices architecture, where I love designing robust API solutions and creating secure middleware for complex integrations.

💼 What I Do Backend Development: Expert in Spring Boot, Spring Cloud, and Spring WebFlux, I create high-performance microservices that drive seamless user experiences. Cloud & DevOps: AWS enthusiast, skilled in using EC2, S3, RDS, and Docker to design scalable and reliable cloud infrastructures. Digital Security: Passionate about securing applications with OAuth2, Keycloak, and digital signatures for data integrity and privacy. 🚀 Current Projects I’m currently working on API integrations with Spring Cloud Gateway and designing an e-invoicing middleware. My projects often involve asynchronous processing, digital signature implementations, and ensuring high standards of security.

📝 Why I Write I enjoy sharing what I’ve learned through blog posts, covering everything from backend design to API security and cloud best practices. Check out my posts if you’re into backend dev, cloud tech, or digital security!

Step 1: Download WinSW

  1. Go to the WinSW GitHub Releases page.

  2. Download the latest .exe file (e.g., WinSW-x64.exe).


Step 2: Rename the .exe File

  • Rename the downloaded .exe file to match your application name. For example:

    • If your Spring Boot application is named MyApp, rename it to MyApp.exe.

Step 3: Create a Configuration File

  1. In the same directory as your renamed .exe file, create an XML configuration file with the same name as the .exe file, but with an .xml extension. For example:

    • MyApp.xml.
  2. Add the following content to the XML file:

<service>
  <id>MyApp</id>
  <name>My Application</name>
  <description>This is my Spring Boot application running as a Windows service.</description>

  <!-- Path to the Java executable -->
  <executable>C:\path\to\java.exe</executable>

  <!-- Path to your Spring Boot JAR -->
  <arguments>-jar C:\path\to\your-spring-boot-app.jar</arguments>

  <!-- Optionally define working directory -->
  <workingdirectory>C:\path\to</workingdirectory>

  <!-- Logging -->
  <logmode>roll</logmode>
</service>
  • Replace C:\path\to\java.exe with the path to your Java installation.

  • Replace C:\path\to\your-spring-boot-app.jar with the full path to your Spring Boot JAR file.


Step 4: Place Your Spring Boot JAR File

  • Ensure your Spring Boot application's JAR file is located at the specified path in the XML file.

Step 5: Test the Configuration

  1. Open a Command Prompt as Administrator.

  2. Navigate to the directory containing the .exe and .xml files.

  3. Run the following command to test:

     MyApp.exe install
    
  4. Start the service:

     MyApp.exe start
    
  5. To check the status of the service:

     MyApp.exe status
    
  6. Stop the service if needed:

     MyApp.exe stop
    

Step 6: Verify the Service

  1. Open the Windows Services Manager:

    • Press Win + R, type services.msc, and hit Enter.
  2. Look for your service by the name you specified in the XML file.

  3. Start or stop the service from the Services Manager to confirm it works.


Step 7: Optional - Configure Automatic Startup

  • Set the service to start automatically:

    1. Open the Services Manager (services.msc).

    2. Right-click your service and select Properties.

    3. Change the Startup type to Automatic.


Step 8: Logs and Troubleshooting

  • Logs are typically stored in the same directory as the .exe file, with files like MyApp.out.log and MyApp.err.log.

  • Check these files for any errors if the service does not start correctly.

More from this blog

Shohanur Rahman's blog

69 posts