Java Service Wrapper

Source: Internet
Author: User

The project needs to run the Java application into a jar package, running in a Linux environment

There is a problem: after the deployment, after the Java-jar Xxx.jar, because of ssh in, so this window is turned off, his process is turned off, this is not acceptable

Target: Boot automatically start, without human intervention, is the Guardian process. The common practice is to write shell scripts, check some online, recommend Java Service Wrapper

Advantages: Most of the systems are supported, can be made into services, can boot

The following is a combination of itself and the network to say:

Reference article address: http://blog.csdn.net/lyflower/article/details/6098025

Below the Linux/opt build Tianlong directory, copy Tianlong.jar to/home/cotton/applications/data_receive/lib directory.

1, download Java Service Wrapper (current version wrapper-linux-x86-64-3.5.26), unzip.
http://wrapper.tanukisoftware.org/
Copy wrapper/src/bin/sh.script.in to/home/cotton/applications/data_receive/bin directory, rename to Datareceive

Copy the wrapper file from the Wrapper/bin directory to the/home/cotton/applications/data_receive/bin directory

Copy wrapper/src/conf/wrapper.conf.in to/home/cotton/applications/data_receive/conf directory, rename to wrapper.conf

Copy the Wrapper/lib directory to the/home/cotton/applications/data_receive/lib directory with 3 files

Libwrapper.so
Wrapper.jar
Wrappertest.jar

2. Modify the/home/cotton/applications/data_receive/bin/datareceive file
App_name= "datareceive"//note here, the application service name should be the same as the datareceive name in the 1th step/home/cotton/applications/data_receive/bin
App_long_name= "Datareceive Application Server"
Wrapper_cmd= "./wrapper"//Here is the path to write correctly, here is the corresponding/home/cotton/applications/data_receive/bin/wrapper this file
Wrapper_conf= ". /conf/wrapper.conf "//The path here is to be written correctly, here is the corresponding/home/cotton/applications/data_receive/conf/wrapper.conf this file
Give Execute permission
chmod 775/home/cotton/applications/data_receive/bin/datareceive
chmod 775/home/cotton/applications/data_receive/bin/wrapper

3. Modify the/home/cotton/applications/data_receive/conf/wrapper.conf file
Wrapper.java.command=/home/cotton/jdk1.7.0_71/bin/java//Here is the installation path to write Java
Use Wrapperstartstopapp so that you can start/stop programs with Start/stop with commands.
Wrapper.java.mainclass=org.tanukisoftware.wrapper.wrapperstartstopapp
#这里添加你用到的jar包文件, from 1.. n You write it all on your own, but wrapper is a must, I use CLASSPATH1 and 2 here.
wrapper.java.classpath.1=. /lib/wrapper.jar
Wrapper.java.classpath.2=. /lib/data_receiver.jar//Here means to put the packaged Tianlong.jar in/home/cotton/applications/data_receive/lib this folder
wrapper.java.classpath.3=. /lib/asterisk-java-0.3.jar
wrapper.java.classpath.4=. /lib/mysql-connector-java-5.1.6-bin.jar
Wrapper.java.classpath.5=/home/cotton/jdk1.7.0_71/lib/dt.jar
Wrapper.java.classpath.6=/home/cotton/jdk1.7.0_71/lib/tools.jar
wrapper.java.classpath.7=. /cofig.properties//This is the configuration file used by the application. If you use an application that needs to be configured, you need to include this file in
wrapper.java.library.path.1=. /lib//Here is the path of the jar package used to represent wrapper, the general default is, the absolute path is:/home/cotton/applications/data_receive/lib
#这个就是你自己可执行程序的主类 (MainClass), in general, is the class that contains the public static void main
Wrapper.app.parameter.1=mainmothed_class
Wrapper.app.parameter.2=1
Wrapper.app.parameter.3=true
Wrapper.app.parameter.4=mainmothed_class
Wrapper.app.parameter.5=true
Wrapper.app.parameter.6=1
Wrapper.app.parameter.7=stop

4, let datareceive boot automatically run
Ln-s/home/cotton/applications/data_receive/bin/datareceive/etc/init.d/datareceive
Ln-s/home/cotton/applications/data_receive/bin/datareceive/etc/rc0.d/datareceive
Ln-s/home/cotton/ Applications/data_receive/bin/datareceive/etc/rc1.d/datareceive
Ln-s/home/cotton/applications/data_receive/ Bin/datareceive/etc/rc2.d/datareceive
Ln-s/home/cotton/applications/data_receive/bin/datareceive/etc/rc3.d/ Datareceive
ln-s/home/cotton/applications/data_receive/bin/datareceive/etc/rc4.d/datareceive
Ln-s/home/ Cotton/applications/data_receive/bin/datareceive/etc/rc5.d/datareceive
Ln-s/home/cotton/applications/data_ Receive/bin/datareceive/etc/rc6.d/datareceive

5. Test Execution Command: service datareceive start|stop|restart|status
When the program runs, the Java Service wrapper generates Wrapper.log logs in the/home/cotton/applications/data_receive/bin/directory,
STATUS | wrapper| 2009/02/25 17:04:01 | --Wrapper Started as Daemon
STATUS | wrapper| 2009/02/25 17:04:01 | Java Service Wrapper Community Edition 3.3.2
STATUS | wrapper| 2009/02/25 17:04:01 | Copyright (C) 1999-2009 tanuki software, ltd.all rights Reserved.
STATUS | wrapper| 2009/02/25 17:04:01 | http://wrapper.tanukisoftware.org
STATUS | wrapper| 2009/02/25 17:04:01 |
STATUS | wrapper| 2009/02/25 17:04:01 | Launching a JVM ...
INFO | JVM 1 | 2009/02/25 17:04:02 | Wrappermanager:initializing ...

The above indicates that it has been configured successfully. If there is an error in the configuration, there will be a hint in wrapper.log.
At the same time, if the program is configured successfully and started, there will be a datareceive.pid in the/home/cotton/applications/data_receive/bin.

Attached directory structure
/home/cotton/applications/data_receive/

/home/cotton/applications/data_receive/bin
| Datareceive
| DataReceive.java.status (automatically generated when the program runs)
| Datareceive.pid (automatically generated when the program runs)
| Datareceive.status (automatically generated when the program runs)
| Wrapper
| Wrapper.log (automatically generated when the program runs)
/home/cotton/applications/data_receive/conf
| Wrapper.conf
/home/cotton/applications/data_receive/lib
| Libwrapper.so
| Wrapper.jar
| Data_receiver.jar.jar
| Wrappertest.jar

Java Service Wrapper

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.