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.
First, you download the binaries here.
Next, the configuration file that defines our Windows service, MyApp.xml, should look like this:
<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>
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:
$ 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.
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.
NSSM is a service helper program similar to srvany and cygrunsrv. It can start any application as an NT service and will restart the service if it fails for any reason.
Installation using the command line
To install a service, run
nssm install <servicename> <application> [<options>]
NSSM will then attempt to install a service which runs the named application with the given options (if you specified any).
Don’t forget to enclose paths in “quotes” if they contain spaces!
If you want to include quotes in the options you will need to “““quote””” the quotes.