The Spring Boot project builds the jar package and registers it as a service on the Windows Server, starting the boot

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.