Spring Boot App as a Service on Windows

 In this section, we present a couple of options that may be used to run a Java JAR as a Windows service


1.Windows Service Wrapper


Due to difficulties with the GPL license of the Java Service Wrapper (see next subsection) in combination with e.g. the MIT license of Jenkins, the Windows Service Wrapper project, also known as winsw, was conceived.


Winsw provides programmatic means to install/uninstall/start/stop a service. In addition, it may be used to run any kind of executable as a service under Windows, whereas Java Service Wrapper, as implied by its name, only supports Java applications.


Finally, you have to rename the winsw.exe to MyApp.exe so that its name matches with the MyApp.xml configuration file. Thereafter you can install the service like so:

  • <service> <id>MyApp</id> <name>MyApp</name> <description>This runs Spring Boot as a Service.</description> <env name="MYAPP_HOME" value="%BASE%"/> <executable>java</executable> <arguments>-Xmx256m -jar "%BASE%\MyApp.jar"</arguments> <logmode>rotate</logmode> </service>


Similarly, you may use uninstall, start, stop, etc.

  • $ MyApp.exe install


2.Java Service Wrapper


In case you don't mind the GPL licensing of the Java Service Wrapper project, this alternative may address your needs to configure your JAR file as a Windows service equally well. Basically, the Java Service Wrapper also requires you to specify in a configuration file which specifies how to run your process as a service under Windows.


This article explains in a very detailed way how to set up such an execution of a JAR file as a service under Windows, so we there's no need to repeat the info.


Source: baeldung.com