Deploying a Springboot application/ JAR as a windows service using winsw

I recently had a task of deploying a JAR application as a windows service on a windows server and came across an easy to setup tool called winsw. In this article I am going to give a step by step guide on how to deploy a JAR executable using winsw and showcase the useful features it has.

Winsw is a windows service wrapper that can run any executable as a windows service. This therefore means its not dependent on jar files but any executable written in any language but in this article we are going to use a JAR file as our executable.

Step 1: Download winsw from their github repository here.

  • You will see a list of .exe files, select the one compatible with your dot net version. For steps on how to check your .Net version here. (I selected Winsw.NET4.exe)

Step 2: Create a new folder or directory and copy the downloaded WinSW.NET4.exe in the folder. You can also add the JAR you want to execute in this directory.

Step 3: Rename the WinSW.NET.exe according to any custom name of your preference. Lets say we rename it windows-service.exe (but you can choose any name you desire)

Step 4: Create an XML file in that directory with the same name as the .exe file. Lets create ours and name it windows-service.xml.

Step 5: Open the empty windows-service.xml and add the following content:

<service>

<id>my-watcher</id>
<name>watcher</name>
<description>This service is for executing the watcher that is actively listening</description>
<executable>java</executable>
<arguments>-jar watcher.jar</arguments>
<log mode=”none”/>

</service>

Note: Edit the arguments according to your project

  • id tag: specifies ID used by windows to identify it as a service and should be unique and contain only alpha numeric characters.
  • name tag: Its the display name of the service created and should also be unique to other services.
  • description tag: holds any custom description of what your service does.
  • executable tag: specifies what kind of executable you are trying to execute as a windows service.
  • arguments tag: specifies the arguments to be passed to the executable.
  • log mode tag: possible values to include are none, append, reset. I chose none because the log file can grow quite big when you chose append and for my usecase I was not quite keen on the logs. For more about logging click here.

There is quite a lot of more useful tags you can utilize depending on your use-case, find more information by clicking here.

Step 6: Open the command prompt in that directory and type <your .exe> install , for example in our case “windows-service.exe install” if all configuration is good it will install the service.

Install command

Step 7: Finally, click on startup menu and search for services and open it and search for your service name. Highlight your service and click run (the green play button) to start your service. The status will then change to running.

Your service will be among the list of services.
After clicking run status becomes Running.

In case you want to uninstall your service, navigate to your service directory in the command prompt and write <your service> uninstall.

If you have reached here you have probably had a successful deployment. Kindly leave some claps if you found this useful.. Happy coding.

Solving real world problems through technology