首先下載java service wrapper工具
http://sourceforge.net/project/showfiles.php?group_id=39428
步驟:
1、解壓縮java service wrapper包,假設目錄為:wrapper_home
2、建立一個目錄比如:D盤server文件夾里面建立bin、conf、logs、lib文件夾。
3、將wrapper_home/bin目錄里wrapper.exe
將wrapper_home/src/bin目錄里App.bat.in
將wrapper_home/src/bin目錄里InstallApp-NT.bat.in
將wrapper_home/src/bin目錄里UninstallApp-NT.bat.in
統一拷貝至server/bin目錄里,并去掉后綴名in。
將wrapper_home/src/conf目錄wrapper.conf.in拷貝至server/conf目錄里去掉后綴名in
再將wrapper_home/lib/目錄里面的wrapper.jar和wrapper.dll拷貝至server/lib目錄里面
4、將你的應用程序打成jar包后放入server/lib目錄里面,如果程序依賴第三方架包,同樣將jar包放入該目錄下。
5、配置server/conf/wrapper.conf文件。
主要修改以下幾項即可:
#你的JVM位置:
wrapper.java.command=%JAVA_HOME%\bin\java
#classpath:里面添加上你要執行的應用程序jar,以及依賴的第三方jar,有多個依次類推
wrapper.java.classpath.1=../lib/應用程序.jar
wrapper.java.classpath.2=../lib/wrapper.jar
wrapper.java.classpath.3=../bin/第三方.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS 此處決定了使用Java Service Wrapper的方式
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
上面紅色字體不能修改成你的執行程序路徑比如
service.server.Serverbegin 否則打成服務后啟動會提示如下錯誤:
ERROR | wrapper | 2010/01/07 15:13:10 | JVM did not exit on request, terminated
STATUS | wrapper | 2010/01/07 15:13:15 | Launching a JVM...
INFO | jvm 3 | 2010/01/07 15:13:16 | [WARN]2010-01-07 15:13:16--服務端啟動
ERROR | wrapper | 2010/01/07 15:13:45 | Startup failed: Timed out waiting for a signal from the JVM.
ADVICE | wrapper | 2010/01/07 15:13:45 |
ADVICE | wrapper | 2010/01/07 15:13:45 | ------------------------------------------------------------------------
ADVICE | wrapper | 2010/01/07 15:13:45 | Advice:
ADVICE | wrapper | 2010/01/07 15:13:45 | The Wrapper consists of a native component as well as a set of classes
ADVICE | wrapper | 2010/01/07 15:13:45 | which run within the JVM that it launches. The Java component of the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper must be initialized promptly after the JVM is launched or the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper will timeout, as just happened. Most likely the main class
ADVICE | wrapper | 2010/01/07 15:13:45 | specified in the Wrapper configuration file is not correctly initializing
ADVICE | wrapper | 2010/01/07 15:13:45 | the Wrapper classes:
ADVICE | wrapper | 2010/01/07 15:13:45 | service.hl7Server.HuaHaiHl7Server
ADVICE | wrapper | 2010/01/07 15:13:45 | While it is possible to do so manually, the Wrapper ships with helper
ADVICE | wrapper | 2010/01/07 15:13:45 | classes to make this initialization processes automatic.
ADVICE | wrapper | 2010/01/07 15:13:45 | Please review the integration section of the Wrapper's documentation
ADVICE | wrapper | 2010/01/07 15:13:45 | for the various methods which can be employed to launch an application
ADVICE | wrapper | 2010/01/07 15:13:45 | within the Wrapper:
ADVICE | wrapper | 2010/01/07 15:13:45 | http://wrapper.tanukisoftware.org/doc/english/integrate.html
#你的Java應用類,
wrapper.app.parameter.1= service.Server.Serverbegin
# 服務名
wrapper.ntservice.name=server
# Display name of the service
wrapper.ntservice.displayname=server
# 服務描述
wrapper.ntservice.description=receive message
其他的配置根據你的需要改變即可
6. 對以上配置的App.bat進行測試,運行App.bat,dos窗口中顯示;
7. 對以上配置的服務進行測試,運行server/bin/InstallApp-NT.bat將把你的應用(此處為server)安裝到Win32系統服務中了。
8. 打開控制面板-管理程序-服務,看到server已經在系統服務中了,其他用法就與我們熟悉的Windows服務一樣了。
bin/App.bat 控制臺方式運行程序
bin/InstallApp-NT.bat 安裝服務
bin/UninstallApp-NT.bat 刪除服務
posted on 2010-01-18 13:10
朔望魔刃 閱讀(3409)
評論(2) 編輯 收藏 所屬分類:
各種配置