First, preface
Since the Java console program was shut down by preventing maintenance personnel from doing so, it was decided to transform it to run as a Windows service. Got a morning at last, the following records, for later inspection.
Second, Java Service Wrapper
Website address: http://wrapper.tanukisoftware.com/doc/english/download.jsp
Javaservicewrapper run Java programs in a daemon or Windows service way. JSW offers four solutions to transform legacy projects to run in the way daemons or Windows services are implemented. It also provides JVM monitoring and automatic restart functionality, which is very powerful anyway.
Way 1:wrappersimpleapp
A program that is used to implement startup and shutdown through the same class.
The official recommendation is to use this method to process the original project, the benefit is simple, and do not modify the original project code.
Step 1: Download and unzip to get the toolkit, directory structure as follows
/
|--Bin,wrapper to control the bat file for Windows services
|--conf,wrapper configuration file
|--Doc, tutorials
|--Lib,wrapper's Dependency package
|--logs, log
|--src, template
|--conf
|--bin
Step 2: Build the project structure: Create a new project publish directory (assuming the agent), then copy the Conf and bin under SRC to the agent, and rename the file under Conf and bin to remove the '. In ' suffix. Then copy the Bin/wrapper.exe to agent/bin/, and then copy the Lib to the agent and get the directory structure as follows
Agent
|--Lib
|--Wrapper.dll
|--Wrapper.jar
|--conf
|--wrapper.conf
|--bin
|--Wrapper.exe
|--a bunch of bat files
Finally, the files of the original project are copied to the bin directory.
Step 3: Configure the parameters of the agent/conf/wrapper.conf
# Configure Java command path Wrapper.java.command=jre/bin/java# Configuring Classpath path (does not modify global environment variables) # If the original project also relies on other jar packages, it needs to be added in Wrapper.java.classpath.1=.. /lib/Wrapper.jarwrapper.java.classpath.2=. # Configure the Lib path wrapper.java.library.path.1=.. /main of the lib# Configuration serviceclass(that is, the program entry class for the original project) Wrapper.app.parameter.1=Agent. daemon# Configuring wrapper log Files Wrapper.logfile=logs/agent.log# Configuring the system service name Wrapper.ntservice.name=agentservice# Configure the name of the system service display Wrapper.ntservice.displayname=agentservice# Configuring the system service Description Wrapper.ntservice.description=agentservice# Configure how the system service is started, with a value range of Auto_start or DEMAND_STARTwrapper.ntservice.starttype=auto_start# Configuration Memory Overflow restarts the service Wrapper.filter.trigger.1001=exceptioninchThread"*"java.lang.OutOfMemoryErrorwrapper.filter.allow_wildcards.1001=TRUEwrapper.filter.action.1001=RESTARTwrapper.filter.message.1001=the JVM has run outof memory.
Step 4: Install and uninstall the service
Click on the corresponding Install.bat and Uninstall.bat.
2. Mode 2:wrapperstartstopapp
For a project like Tomcat, the startup program and the shutdown program are separate items. This method also does not have to modify the original project code.
3. Mode 3:wrapperlistener
The method needs to modify the code of the original project, but the most flexible.
4. Mode 4:wrapperjarapp
For cases where the original project has been packaged as a jar or war package, the configuration is similar to ' Wrappersimpleapp ', but ' wrapper.app.parameter.1=jar or War package path '. This method also does not need to modify the original project code
Iii. Summary
Official documents to JBoss as an example of the use of Wrappersimpleapp, very difficult to understand, fortunately there are previous records of the actual process I was saved from the Abyss, thanks.
Respect the original, reprint please indicate from: http://www.cnblogs.com/fsjohnhuang/p/4019267.html ^_^ Fat Boy John
Iv. references
http://blog.csdn.net/arjick/article/details/4526392
Java Magic Hall: running Java programs as a Windows service