Http://www.cppblog.com/aurain/archive/2014/01/23/205534.aspx
1 Prepare
Using the tool Procrun (http://commons.apache.org/proper/commons-daemon/procrun.html), (http://archive.apache.org/dist/ commons/daemon/binaries/windows/), Tomcat also uses it as a service program. The latest version is Commons-daemon-1.0.15-bin-windows.zip (update 2013-04-02 14:03), 32-bit system use directory under the default prunsvr.exe,64 bit system amd64\ Prunsvr.exe.
Assuming that the name of the jar package that needs to be deployed is Myservice.jar, we first create the directory myservice, copy the Myservice.jar and Prunsvr.exe to the MyService directory, and rename Prunsvr.exe to MyService.exe. If Myservice.jar needs to use a configuration file, such as a configuration file in the Conf directory, then the Conf directory needs to be copied to the MyService directory.
2 Installation Scripts
@echo off
SET pr_path=%cd%
SET Pr_exe=myservice.exe
SET pr_service_name= MyService
SET pr_display_name= MyService
SET pr_description= MyService for Xxx,copyright XXXXXX.
SET pr_jar= Myservice.jar
SET Start_class=com.xxx.myservice
SET Start_method=main
SET Stop_class=java.lang.system
SET Stop_method=exit
SET stop_params=0
%pr_path%\%pr_exe%//is//%pr_service_name%--displayname= "%pr_display_name%"--description= "%PR_DESCRIPTION%"-- Install= "%pr_path%\%pr_exe%"--jvmms=2000--jvmmx=2000--jvmss=1024 ++dependson=mssqlserver--Jvm=auto--Startup= Auto--STARTMODE=JVM--startclass=%start_class%--startmethod=%start_method%--STOPMODE=JVM--StopClass=%STOP_CLASS %--stopmethod=%stop_method% ++stopparams=%stop_params%--classpath= "%pr_path%\%pr_jar%"
%pr_path%\%pr_exe%//es//%pr_service_name%
@echo on
3 Unload Script
@echo off
SET pr_path=%cd%
SET Pr_service_name=myservice
SET pr_exe= MyService.exe
%pr_path%\%pr_exe%//ds//%pr_service_name%
@echo on
4 Prunsvr parameter Description
PRUNSVR is a command-line tool that can be used to package ordinary programs into service programs, not only for Java programs, but also for other EXE executables.
PRUNSVR command Format//xx[//servicename].
Main command line
TS Console mode operation
is installation service
ES Start-up service
SS Stop Service
DS Delete Service
Main command line arguments
command-line parameter prefixes are--。 If the prefix is + +, then these parameters are appended to the option that already exists.
Description of the--description service name (maximum 1024 characters)
--displayname the name of the service display
--install Procrun.exe//rs//servicename installation image
--startup service startup mode, auto Auto or manual manual, default to Manual
The--type service type can be an interactive desktop program interactive. Use and this option are limited to the local system account
Other services that the ++dependson service needs to rely on. Depending on the service use # or; Character segmentation
--classpath for Java classes, set the jar package path
--jvmms Initial memory pool, unit MB
--JVMMX Maximum memory pool, Unit MB
--JVMSS thread stack, per KB
Please refer to the official Help documentation for more assistance.
Package the jar package into a service program under--windows