Java Service Wrapper (http://wrapper.tanukisoftware.com/doc/english/integrate.html) is a tool that provides a set of Binar IES and scripts for different architectures and operating systems The Allow Java developers to run a Java application as A service daemon.
For this post I used a 64-bit CentOS PC as a server.
The source code of my test program is:
ImportJava.text.SimpleDateFormat;Importjava.util.Date;/** * @authorxingning OU*/ Public classSegmentservicemain { Public Static voidMain (string[] args) {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); while(true) {System.out.println (Sdf.format (NewDate ())); Try{Thread.Sleep (2000L); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
1. Preparing the Environment:
mkdir -p/data/app/segment/mkdir -p/data/app/segment/mkdir -p/data/ app/segment/CP -R segment.jar/data/app/segment/bin/
2. Download and install Java Service Wrapper for Linux:
wget http://wrapper.tanukisoftware.com/download/3.5.25/wrapper-linux-x86-64-3.5.25.tar.gz
3. Extract the package and copy the files needed:
# tar -zxvf wrapper-linux-x86-64 - Span style= "color: #800080;" >3.5 . 25 . tar .gz# CD wrapper -linux-x86-64 -3.5 . 25 # CP bin/wrapper/data/app/segment/bin/# CP src/bin/in /data/app/segment/bin/# CP Lib/* /data/app/segment/bin/# CP conf/ wrapper.conf/data/app/segment/conf/
4. Rename the Servcie script and set correct permissions:
# cd/data/app/segment/bin/mv Sch.script. in segment-chmod +x Segment-servcie
5. changeing some directive from the Config file (wrapper.conf)
6. Edit inti Script (Segment-service)
7. Run the application at boot time:
Ln -s/data/app/segment/bin/segment-service/etc/init.d/segment-235 Segment-service on
Reference:
http://opentodo.net/2013/03/deploying-java-unix-daemon-with-java-service-wrapper/
How to deploy a Java Linux Daemon with Java servcie Wrapper