標籤:specified .so zip modify desc default using check png
在windows上運行jar包,需要在工作目錄下使用命令列運行jar包,這樣會出現一個命令列視窗。而且這個命令列視窗有可能會不小心被關閉,且伺服器啟動後需要人為去點擊開啟。
對於有些服務性的程式來說,我們需要將其部署為windows服務,在系統啟動的時候自動啟動。
前面我使用了yajsw來進行,請參考我的博文:http://www.cnblogs.com/kxxx/p/6744309.html
但本次在另外一台伺服器上進行處理時,安裝了服務之後不能開啟,服務每次都報找不到指定檔案的錯誤,試了很久也未搞定,不得不將眼光轉移到另外一款軟體Java Service Wrapper.
我在使用之前參考了如下文章:
http://blog.csdn.net/fly_sky520/article/details/8809325
http://blog.csdn.net/lqclh502/article/details/51557015
參考了之後,準備下載檔案,:http://wrapper.tanukisoftware.com/doc/english/download.jsp
由於我的伺服器是64位的,在下載的時候發現64位下沒有免費版的,又擔心其他2個版本要收費,故也沒有下載其他2個版本,在網上尋找破解版的,最後在這個網址上下載了一個:
https://www.krenger.ch/blog/java-service-wrapper-3-5-14-for-windows-x64/
我下載的版本是3.5.14。
然後開始進行配置:
1.在我的伺服器上建立了一個檔案夾,取名 jar_jsw。
2.解壓下載的zip包。
3.在建立的檔案夾jar_jsw下建立bin、conf、lib、logs檔案夾,並且將需要啟動的jar包複製到jar_jsw目錄下,我的jar包為:processapp.jar
4.把解壓後的檔案夾中src\bin中的檔案複製到建立的jar_jsw/bin檔案夾下面。並把所有檔案的in尾碼去掉。同時把解壓後檔案夾中bin下的wrapper.exe也放到建立的bin下
5.把解壓後的檔案夾中src\conf中的檔案複製到建立的conf檔案夾中。把in尾碼去掉,其實只有一個檔案,即wrapper.conf。
6.把解壓後的檔案夾中lib中的wrapper.jar與wrapper.dll放到建立的lib下面。同時把啟動jar包程式所需要的第三方jar包也放在這裡。
7.開始配置wrapper.conf檔案。配置選項請參見其它的文章。
8.配置以後,點擊bin檔案夾下面的App.bat進行測試,如果能夠在console中出現正常結果的話就表明配置正確。然後點擊InstallApp-NT.bat安裝服務,也可以點擊UninstallApp-NT.bat卸載服務。成功安裝服務後可以在window服務管理中看到。
註:我的jar包使用了 System.getProperty("user.dir") 來擷取工作目錄,按照預設的設定,我啟動的程式要報錯,總是報找不到檔案。於是我在網上查看jsw是否有修改工作目錄的參數,最後在此進行了參考:
https://wrapper.tanukisoftware.com/doc/english/properties.html
發現有 wrapper.working.dir 這個設定,於是參考其設定:https://wrapper.tanukisoftware.com/doc/english/prop-working-dir.html
當修改了工作目錄後,其對應的classpath等參數也需要做相應的變動,如所示的參數。我修改之後一切OK。
至此,我將jar包封裝成windows服務完成。
寫在後面,我發現activemq也是使用此方法安裝的服務。
下面給出我的設定檔:
encoding=UTF-8# Configuration files must begin with a line specifying the encoding# of the the file.#********************************************************************# Wrapper License Properties (Ignored by Community Edition)#********************************************************************# Professional and Standard Editions of the Wrapper require a valid# License Key to start. Licenses can be purchased or a trial license# requested on the following pages:# http://wrapper.tanukisoftware.com/purchase# http://wrapper.tanukisoftware.com/trial# Include file problems can be debugged by removing the first ‘#‘# from the following line:##include.debug# The Wrapper will look for either of the following optional files for a# valid License Key. License Key properties can optionally be included# directly in this configuration file.#include ../conf/wrapper-license.conf#include ../conf/wrapper-license-%WRAPPER_HOST_NAME%.conf# The following property will output information about which License Key(s)# are being found, and can aid in resolving any licensing problems.#wrapper.license.debug=TRUE#********************************************************************# Wrapper Localization#********************************************************************# Specify the locale which the Wrapper should use. By default the system# locale is used.#wrapper.lang=en_US # en_US or ja_JP# Specify the location of the Wrapper‘s language resources. If these are# missing, the Wrapper will default to the en_US locale.wrapper.lang.folder=../lang#********************************************************************# Wrapper Java Properties#********************************************************************# Java Application# Locate the java binary on the system PATH:wrapper.java.command=C:\Program Files\Java\jdk1.8.0_25/bin/java# Specify a specific java binary:#set.JAVA_HOME=/java/path#wrapper.java.command=%JAVA_HOME%/bin/java# Tell the Wrapper to log the full generated Java command line.#wrapper.java.command.loglevel=INFO# Java Main class. This class must implement the WrapperListener interface# or guarantee that the WrapperManager class is initialized. Helper# classes are provided to do this for you. See the Integration section# of the documentation for details.wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp# Java Classpath (include wrapper.jar) Add class path elements as# needed starting from 1#wrapper.java.classpath.1=../lib/wrapper.jar#wrapper.java.classpath.2=../processapp.jar#wrapper.java.classpath.3=../lib/*#更改了working.dir之後.路徑將要隨之變化wrapper.working.dir=../wrapper.java.classpath.1=lib/wrapper.jarwrapper.java.classpath.2=processapp.jarwrapper.java.classpath.3=lib/*# Java Library Path (location of Wrapper.DLL or libwrapper.so)wrapper.java.library.path.1=lib# Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode.wrapper.java.additional.auto_bits=TRUE# Java Additional Parameterswrapper.java.additional.1=# Initial Java Heap Size (in MB)#wrapper.java.initmemory=3# Maximum Java Heap Size (in MB)#wrapper.java.maxmemory=64# Application parameters. Add parameters as needed starting from 1wrapper.app.parameter.1=com.el.cardata.processapp.HCAPPStart#********************************************************************# Wrapper Logging Properties#********************************************************************# Enables Debug output from the Wrapper.# wrapper.debug=TRUE# Format of output for the console. (See docs for formats)wrapper.console.format=PM# Log Level for console output. (See docs for log levels)wrapper.console.loglevel=INFO# Log file to use for wrapper output logging.wrapper.logfile=logs/wrapper.log#wrapper.pidfile=bin/wrapper.pid#wrapper.java.pidfile=bin/java.pid# Format of output for the log file. (See docs for formats)wrapper.logfile.format=LPTM# Log Level for log file output. (See docs for log levels)wrapper.logfile.loglevel=INFO# Maximum size that the log file will be allowed to grow to before# the log is rolled. Size is specified in bytes. The default value# of 0, disables log rolling. May abbreviate with the ‘k‘ (kb) or# ‘m‘ (mb) suffix. For example: 10m = 10 megabytes.wrapper.logfile.maxsize=0# Maximum number of rolled log files which will be allowed before old# files are deleted. The default value of 0 implies no limit.wrapper.logfile.maxfiles=0# Log Level for sys/event log output. (See docs for log levels)wrapper.syslog.loglevel=NONE#********************************************************************# Wrapper General Properties#********************************************************************# Allow for the use of non-contiguous numbered propertieswrapper.ignore_sequence_gaps=TRUE# Do not start if the pid file already exists.wrapper.pidfile.strict=TRUE# Title to use when running as a consolewrapper.console.title=CJ_MessagePro#********************************************************************# Wrapper JVM Checks#********************************************************************# Detect DeadLocked Threads in the JVM. (Requires Standard Edition)wrapper.check.deadlock=TRUEwrapper.check.deadlock.interval=60wrapper.check.deadlock.action=RESTARTwrapper.check.deadlock.output=FULL# Out Of Memory detection.# (Simple match)wrapper.filter.trigger.1000=java.lang.OutOfMemoryError# (Only match text in stack traces if -XX:+PrintClassHistogram is being used.)#wrapper.filter.trigger.1000=Exception in thread "*" java.lang.OutOfMemoryError#wrapper.filter.allow_wildcards.1000=TRUEwrapper.filter.action.1000=RESTARTwrapper.filter.message.1000=The JVM has run out of memory.#********************************************************************# Wrapper Email Notifications. (Requires Professional Edition)#********************************************************************# Common Event Email settings.#wrapper.event.default.email.debug=TRUE#wrapper.event.default.email.smtp.host=<SMTP_Host>#wrapper.event.default.email.smtp.port=25#wrapper.event.default.email.subject=[%WRAPPER_HOSTNAME%:%WRAPPER_NAME%:%WRAPPER_EVENT_NAME%] Event Notification#wrapper.event.default.email.sender=<Sender email>#wrapper.event.default.email.recipient=<Recipient email># Configure the log attached to event emails.#wrapper.event.default.email.attach_log=TRUE#wrapper.event.default.email.maillog.lines=50#wrapper.event.default.email.maillog.format=LPTM#wrapper.event.default.email.maillog.loglevel=INFO# Enable specific event emails.#wrapper.event.wrapper_start.email=TRUE#wrapper.event.jvm_prelaunch.email=TRUE#wrapper.event.jvm_start.email=TRUE#wrapper.event.jvm_started.email=TRUE#wrapper.event.jvm_deadlock.email=TRUE#wrapper.event.jvm_stop.email=TRUE#wrapper.event.jvm_stopped.email=TRUE#wrapper.event.jvm_restart.email=TRUE#wrapper.event.jvm_failed_invocation.email=TRUE#wrapper.event.jvm_max_failed_invocations.email=TRUE#wrapper.event.jvm_kill.email=TRUE#wrapper.event.jvm_killed.email=TRUE#wrapper.event.jvm_unexpected_exit.email=TRUE#wrapper.event.wrapper_stop.email=TRUE# Specify custom mail contentwrapper.event.jvm_restart.email.body=The JVM was restarted.\n\nPlease check on its status.\n#********************************************************************# Wrapper Windows NT/2000/XP Service Properties#********************************************************************# WARNING - Do not modify any of these properties when an application# using this configuration file has been installed as a service.# Please uninstall the service before modifying this section. The# service can then be reinstalled.# Name of the servicewrapper.name=CJ_MessagePro# Display name of the servicewrapper.displayname=CJ_MessagePro# Description of the servicewrapper.description=CJ_MessagePro# Service dependencies. Add dependencies as needed starting from 1wrapper.ntservice.dependency.1=# Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_STARTwrapper.ntservice.starttype=AUTO_START# Allow the service to interact with the desktop.wrapper.ntservice.interactive=false
使用Java Service Wrapper將jar包安裝成Windows服務