JavaService
目錄
JavaService
官方網址
為什麼選擇JavaService
JavaService如何使用
JavaService參數說明
相關參數的作用說明如下
項目常用寫法
參數解釋說明
官方網址
http://javaservice.ow2.org/index.html
為什麼選擇JavaService
- JavaService是一個開源免費的軟體,大小隻有100多kB,區分32位,64位jdk,可以跟據需要下載下傳,
- 市面上也有其他的将java程式打成windows服務的軟體,比如Java Service Wrapper,,但是64位jdk版本的是需要收費的,而目前大部分java程式都是在64為jdk上運作,是以有局限性
JavaService如何使用
JavaService參數說明
JavaService一共提供了8個參數可供選擇,其中我們隻需要關心安裝NT服務的-install參數和解除安裝NT服務的-uninstall參數。
使用-install參數安裝NT服務時還需要提供與服務相關的其它一些參數,其指令格式如下:
JavaService -install service_name jvm_library [jvm_options]
-start start_class [-method start_method] [-params (start_parameters)]
[-stop start_class [-method stop_method] [-params (stop_parameters)]]
[-out out_log_file] [-err err_log_file]
[-current current_dir]
[-path extra_path]
[-depends other_service]
[-auto | -manual]
[-shutdown seconds]
[-user user_name -password password]
[-append | -overwrite]
[-startup seconds]
[-description service_desc]
相關參數的作用說明如下
service_name: The name of the service.
jvm_library: The location of the JVM DLL used to run the service.
jvm_option: An option to use when starting the JVM, such as:
"-Djava.class.path=c:/classes" or "-Xmx128m".
start_class: The class to load when starting the service.
start_method: The method to call in the start_class. default: main
start_parameters:Parameter(s) to pass in to the start_method.
stop_class: The class to load when stopping the service.
stop_method: The method to call in the stop_class. default: main
stop_parameters: Parameter(s) to pass in to the stop_method.
out_log_file: A file to redirect System.out into. (gets overwritten)
err_log_file: A file to redirect System.err into. (gets overwritten)
current_dir: The current working directory for the service.
Relative paths will be relative to this directory.
extra_path: Path additions, for native DLLs etc. (no spaces)
other_service: Single service name dependency, must start first.
auto / manual: Startup automatic (default) or manual mode.
seconds: Java method processing time (startup:sleep, shutdown:timeout).
user_name: User specified to execute the service ([email protected]).
password: Password applicable if user specified to run the service.
append / overwrite: Log file output mode, append (default) or overwrite.
service_desc: Text describing installed service (quoted string, max 1024).
項目常用寫法
JavaService.exe -install ECService "%JAVA_HOME%/jre/bin/server/jvm.dll" -Djava.ext.dirs="%JAVA_HOME%/jre/lib/ext" -Xms128m -Xmx512m -Djava.class.path="JAVA_HOME%/lib/tools.jar;c:/ECService/ec.jar" -start com.ecservice.ECService -out "%CD%/out.log" -err "%CD%/err.log" -current "%CD%" -auto
參數解釋說明
JavaService.exe //JavaService程式,自己選32位還是64位
-install ECService //服務名,根據自己的需要取,比如ECService
"%JAVA_HOME%/jre/bin/server/jvm.dll" //jdk環境下的配置,基本固定寫法-Djava.ext.dirs="%JAVA_HOME%/jre/lib/ext" //擴充依賴包路徑
-Xms128m -Xmx512m //程式堆棧記憶體設定
-Djava.class.path="%JAVA_HOME%/lib/tools.jar;c:/ECService/ec.jar"//程式依賴包,配置檔案等,比如lib,config
-start com.ecservice.ECService //系統啟動的主類,一般main方法所在類的全路徑
-out "%CD%/out.log" -err "%CD%/err.log" //日志,一般不使用,跟項目自帶的log4j2不沖突,但會有兩套日志,一般用于錯誤排查
-current "%CD%" //項目運作的目前目錄
-auto //自動
-Dfile.encoding=utf-8 //編碼格式
-DEBUG_ARGS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 //dubeg模式