Background:
Web project developed with spring boot, packaged to generate a jar package that you want to deploy in Windows Server
Try:
1, Spring boot generated jar package, can be run directly with Java-jar, but the premise is to log on the user, and log off the user will exit the program, so it is not trustworthy.
2, the use of scheduled tasks, write a bat batch file, which writes Java-jar run the program, and then the bat file as a scheduled task to run; The result may be that the system resources were not prepared when the task started, so it did not succeed.
Final scenario: Using WINSW
WINSW is an open source project, and the program and source code can be downloaded in the Git hub: https://github.com/kohsuke/winsw/releases
WINSW is a software that can register any application as a service
How to use:
1, download EXE file, assuming renamed into Winsw.exe
2. Create an XML file with the same name under the same directory, such as Winsw.xml
One of the parameters to see for yourself.
<Service> <ID>myapp</ID> <name>MyApp</name> <Description>to start my app as a service.</Description> <executable>Java</executable> <arguments>-xmx256m-jar C:\myApp.jar "--server.port=80</arguments> <LogMode>Rotate</LogMode></Service>
3. Using cmd, go to the Winsw.exe folder with the CD command and execute the command
Install service command: MyApp.exe install
Uninstall Service command: MyApp.exe Uninstall
4, open the system service function: Run--Enter services.msc, you can see your own named service MyApp
5, set the service to automatic, and enable can
The Spring Boot project builds the jar package and registers it as a service on the Windows Server, starting the boot