Register a Java program as a Windows service
Operating environment
The computer should have a java runtime environment.
Requires software
Java Service Wrapper
Download link: http://sourceforge.net/projects/wrapper/
configuration process
First, package the java program into a jar package.
Decompress the Java Service Wrapper package.
For example, if the program project directory to be registered as a service is workapp, then create three folders under this directory: bin, conf, lib.
Copy Wrapper.exe in the bin directory of the Java Service Wrapper package, App.bat.in, InstallApp-NT.bat.in, UninstallApp-NT.bat.in files in the src/bin directory to the bin directory of the workapp , and renamed to App.bat, InstallApp-NT.bat, UninstallApp-NT.bat respectively.
Copy Wrapper.DLL and wrapper.jar in the lib directory of the Java Service Wrapper package to the lib directory of the workapp. And copy the jar of the project and the jars used to this directory.
Copy the wrapper.conf.in in the srcconf directory of the Java Service Wrapper package to the conf directory of the workapp, and name it wrapper.conf.
Modify the wrapper.conf configuration file, as follows:
Mainly modify the following items:
JVM location:
wrapper.java.command=C:\jdk1.5.0_07\bin\javaOperating parameters: such as:
wrapper.java.additional.1=-Dprogram.name=run.batAll jar packages required by your Java program must be marked here, pay attention to the correct path:
wrapper.java.classpath.1=../lib/wrapper.jar wrapper.java.classpath.2=../lib/test_fat.jar ...The directory where your Wrapper.DLL or wrapper.jar is located
wrapper.java.library.path.1=../libMAIN CLASS This determines the way to use the Java Service Wrapper
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleAppThe runtime class of your Java application
wrapper.app.parameter.1=com.tes.TestjarRegister as the name and display name of the service, you can set it as you like
wrapper.ntservice.name=testService wrapper.ntservice.displayname=testServiceservice description information
wrapper.ntservice.description = testService
After the modification is completed, run MyApp.bat to run your java program. Here you can test whether the configuration is correct. If it can run, it proves that the configuration is ok.
Run InstallApp-NT.bat to register the service, and UninstallApp-NT.bat to cancel the service.
After running the registration service InstallApp-NT.bat, you can see the service name you registered in Control Panel - Management Program - Service. (eg: testService)