How to use Java Service Wrapper to wrap java program as a service? Provide the simplest java program source code

1, use the tool - java service wrapper

2, create a new folder, in the folder directory and then create lib, bin, conf, logs, classes folder

3, download the wrapper folder wrapper.jar, wrappertest.jar, wrapper.dll copied to the new lib, bin, conf, logs, classes folder

3, downloaded wrapper folder wrapper.jar, wrappertest.jar, wrapper.dll copy to the new folder wrapper.jar, wrappertest.jar, wrapper.dll. wrappertest.jar,wrapper.dll in the downloaded wrapper's folder to the newly created lib folder

Copy InstallApp-NT.bat, PauseApp-NT.bat, ResumeApp-NT.bat, StartApp-NT.bat, StopAppNT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, UninstallApp- NT.bat, StopAppNT.bat, StopAppNT.bat, and UninstallApp- NT.bat. UninstallApp-NT.bat, StartApp-NT.bat, StopAppNT.bat, UninstallApp- NT.bat, and wrapper.exe to the bin directory;

Copy wrapper.conf to the conf directory;

Copy wrapper.log to the logs directory;

Type the java program that you want to install as a service into a jar package. (here mine is TestServer.jar), and put it into the classes directory together with other required jar packages.

4. Configure the wrapper.conf file in the conf directory:

Here's just a list of what needs to be changed

4.1 wrapper.java.command=java

Specify the jre, if you have configured the machine with the jre, then this item doesn't need to be changed; otherwise you need to copy jre to the wrapper path. jre to the wrapper path

(and bin in the same level)

Also modify wrapper.java.command=... /jre/bin/java.exe

4.2 List the jar packages needed to run the program. wrapper.jar is required

wrapper.java.classpath.1=. /lib/wrapper.jar

wrapper.java.classpath.2=. /classes/TestServer.jar

wrapper.java.classpath.2=. /classes/classes12.jar

4.3 Specify the main class of the program

wrapper.app.parameter.1=test.TestServer

4.4 Console runtime name

wrapper.console. title=TestServer

4.5 Name of the specified service

wrapper.ntservice.name=TestServer

4.6 Display name of the windows service

wrapper.ntservice. displayname=TestServer

4.7 service description

wrapper.ntservice.description=TestServer

4.8 startup mode, default is self-start AUTO_START or DEMAND_START

wrapper.ntservice.starttype=AUTO_START

5, run InstallApp-NT.bat to install the service, run StartApp-NT.bat to start the service

Abnormal errors can be viewed in the logs directory of the log file

6 Precautions:

6.1. Do not change the relative paths of the files

6.2. Do not move files and folders after installing the service

6.3. Perhaps you should clean up the logs/wrapper.log log file periodically to prevent the log file from becoming too large

6.4. Back up the database and the data file

Can refer to /headmerk/item/745022aacdf45613a9cfb730