Light-4J is packaged as a fatjar, and normally would be running in the docker container during production; however, it can be executed on a Windows or Linux host machine or VM with the following command.
java -jar filename.jar
For production deployment, you want to make sure that when your host server/VM is restarted, the application will be restarted automatically.
The following describes step-by-step how you can create a Windows service for your
Light-4J application or any Java application that can be packaged in a fatjar.
There are two different options but the first option is more generic and popular.
Windows Service Wrapper
Due to difficulties with the GPL license of the Java Service Wrapper
(the second option below) in combination with e.g. the MIT license of Jenkins,
the Windows Service Wrapper project, also known as winsw,
is the best choice.
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.
Next, the configuration file that defines our Windows service, MyApp.xml, should
look like this:
<description>This runs Spring Boot as a Service.</description>
<env name="MYAPP_HOME" value="%BASE%"/>
<arguments>-Xmx256m -jar "%BASE%\MyApp.jar"</arguments>
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
$ MyApp.exe install
Similarly, you may use uninstall, start, stop, etc.
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 Server hosts light-gateway
This is contributed from one of our customers and it works very reliable with auto restart if the server instance is down.