將java 應用程式打包成linux下的服務 1
本文介紹如何使用java wrapper service,步驟如下:(已在CentOS5.1 linux下測試通過)
1.從http://wrapper.tanukisoftware.org/doc/english/download.jsp
下載 wrapper-linux-x86-32-3.3.1.tar(請使用Community版本,因Professional和Standard版本需要購買Licenses);
2.解壓wrapper-linux-x86-32-3.3.1.tar為wrapper-linux-x86-32-3.3.1;
3.準備應該程式(app)的目錄,包括bin,conf,lib,logs:
4.拷貝wrapper-linux-x86-32-3.3.1\bin\wrapper(為二進位檔案) 到bin\;
5.拷貝wrapper-linux-x86-32-3.3.1\src\bin\sh.script.in到bin\,並改名為app,將app用到的設定檔都拷貝到該目錄下,包括.ini,.xml;
6.拷貝wrapper-linux-x86-32-3.3.1\src\conf\wrapper.conf.in到conf\,並改名為wrapper.conf;
7.拷貝wrapper-linux-x86-32-3.3.1\lib\wrapper.jar,libwrapper.so到lib\,將app用到的jar包也拷貝到該目錄下;
8.編輯app,設定應用程式的名稱(編輯時請使用NotePad2或EditPlus)
# Application
APP_NAME="MailSender"
APP_LONG_NAME="MailSender Application"
9.編輯wrapper.conf
#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
wrapper.java.command=/usr/java/jdk1.5.0/bin/java
# 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=../lib/classes12.jar #其它引入jar
wrapper.java.classpath.3=../lib/activation.jar #其它引入jar
wrapper.java.classpath.4=../lib/mail.jar #其它引入jar
wrapper.java.classpath.5=../lib/App.jar #當前應用jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib #Windows 版本使用Wrapper.DLL,Linux版本使用libwrapper.so
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=com.wisdom.mail.Main #app應用啟動類
#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=AppName Application
10.使用ssh將app目錄上傳到linux伺服器的/usr/local/app下;
11.登陸ssh,執行:
#chmod 755 /usr/local/app
#cd /usr/local/app/bin
#sudo chmod 755 app
#sudo chmod 755 wrapper
完成部署;
最後一個命令解決:Unable to locate any of the following binaries:
/app/bin/./wrapper-linux-x86-32
/app/bin/./wrapper-linux-x86-64
/app/./wrapper (Found but not executable.) 問題;
12.執行命令:/usr/local/app/bin/app console|start|stop|restart 即可以啟動服務了。
如果要檢查服務是否執行正常,可先使用console參數,如果正常就可以使用start來啟動服務了。
Usage: /usr/local/TserverProxy/bin/app [ console | start | stop | restart | condrestart | status | install | remove | dump ]
Commands:
console Launch in the current console.
start Start in the background as a daemon process.
stop Stop if running as a daemon or in another console.
restart Stop if running and then start.
condrestart Restart only if already running.
status Query the current status.
install Install to start automatically when system boots.
remove Uninstall.
dump Request a Java thread dump if running.