The Springboot Java project as a windows service starts

After the Java project packaged in the Windows system, using java - jar xx.jar start, then there would have been a cmd window, looks inconvenient, but if more than one server, then the public, what if someone turned off trouble, so if the jar package is registered as a windows service can run in the background, is also very easy to start and stop

First, write bat file to start the jar

1, the new one called fmstart.bat, open the editor, writes the following

E:
cd E:/springboot
java -jar fmstart-0.0.1-dev.jar
exit

2, then save it. ok, next time you start, you can click on fmstart.bat started.

PS: in fact, the batch file, saving knock open the cmd command of time, but may also have the presence of CMD window

Two, windows start menu, add a shortcut to start

1, win + R open the Run window, enter the shell: Startup;
2, the fmstart.bat, create a shortcut, and the shortcut to copy the startup file entry.

Restart the computer and see the familiar interface, start successfully.

PS: The second not tried, it is the third major

Third, the use winsw will springboot packaged jar local service registration system

1, start the download github winsw, Download https://github.com/kohsuke/winsw , from
https://github.com/kohsuke/winsw/releases download the two files directly required
2, Git Hub downloaded WinSW.NET4.exe and sample-minimal.xml springboot project documents and a jar in the same folder.
3, winsw execute the program needs to be changed to xml with the same name, project name + Service recommended naming, such as: WinSW.NET4.exe into myProjectService.exe, sample-minmal.xml into myProjectService.xml.
4, edit myProjectService.xml file, as follows

<configuration>
<!--安装成Windows服务后的服务名-->
<id>myProjectServiceID</id>
<!--显示的服务名称-->
    <name>myProjectServiceName</name>
    <!--对服务的描述-->
<description>此处可填写该服务的描述</description>
    <!--这里写java的路径,如何配置了环境变量直接写"java"就行-->
    <executable>java</executable>
<!--Xmx256m 代表堆内存最大值为256MB -jar后面的是项目名-->
    <arguments>-Xmx256m -jar myProject.jar</arguments>
    <!--日志模式-->
 <logmode>rotate</logmode>
</configuration>

5, open the service function: Run - type cmd, and then proceeds to myProjectService.exe the folder, and then execute the command to install the service command: myProjectService.exe install.

6, command prompt and enter the command "net start myProjectServiceName" to start the service.
7, open the service function: Run - type services.msc, you can see his name service myProjectServiceName.
8, test: restart the computer after the service starts automatically, step 6 can check for success.
9, remove the service in two steps: 1 stop service; 2 remove services are implemented in the command line interface.
Command prompt and enter the command "net stop myProjectServiceName" stop running services.
Command prompt and enter the command "myProjectService.exe uninstall" to delete the service
of all of the above 10. The command can be written in a batch file, the deployment can be achieved a key deployed.
E.g. myProjectStart.bat follows:
myProjectService.exe the install
NET Start myProjectServiceName

For example myProjectStop.bat follows:
NET STOP myProjectServiceName
myProjectService.exe Uninstall
11. If not find a cause can view the log, the log file in the same directory

PS: to step 5 when you can use the command directly open the seventh step of the list of services, find their name launched a direct service, since no longer have to deal with annoying CMD window

Author: az44yao
Source: CSDN
Original: https://blog.csdn.net/az44yao/article/details/85166686
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin blog.csdn.net/rui15111/article/details/89360290