JAVA基础应用——java程序在centos后台运行
来源:互联网 发布:安卓ssr软件 编辑:程序博客网 时间:2024/05/16 13:47
方法1 使用nohup命令
nohup java -jar test.jar >/dev/null &
方法2 使用JavaServiceWrapper
Java Service Wrapper把java程序打包为服务。目前支持4种打包方式。
- WrapperSimpleApp
使用WrapperSimpleApp helper class来运行程序。 - WrapperStartStopApp
使用WrapperStartStopApp helper class - WrapperListener
建一个类implements the WrapperListener interface - WrapperJarApp
使用WrapperJarApp helper class
几种方式的具体描述,参见这里:
https://wrapper.tanukisoftware.com/doc/english/integrate.html
1. 类要implements Runnable
public class myclass implements Runnable{ public myclass() { // register a shutdown hook for this class. // a shutdown hook is an initialzed but not started thread, which will get up and run // when the JVM is about to exit. this is used for short clean up tasks. Runtime.getRuntime().addShutdownHook(new Thread(this)); System.out.println(">>> shutdown hook registered"); }}
2. 进程结束时运行的程序写在这里
public void run() { //结束进程时运行这里 }
3. 创建4个目录
mkdir -p /home/ftpuser/testapp/binmkdir -p /home/ftpuser/testapp/confmkdir -p /home/ftpuser/testapp/logsmkdir -p /home/ftpuser/testapp/libmkdir -p /home/ftpuser/testapp/classescp -r testapp.jar /home/ftpuser/testapp/classes/cd /home/ftpuserwget http://wrapper.tanukisoftware.com/download/3.5.25/wrapper-linux-x86-64-3.5.25.tar.gztar -zxvf wrapper-linux-x86-64-3.5.25.tar.gzcd wrapper-linux-x86-64-3.5.25cp bin/wrapper /home/ftpuser/testapp/bin/cp src/bin/sh.script.in /home/ftpuser/testapp/bin/cp lib/* /home/ftpuser/testapp/lib/cp conf/wrapper.conf /home/ftpuser/testapp/conf/
4. 修改 wrapper.conf
修改主类名wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp修改classpathwrapper.java.classpath.1=../lib/wrapper.jarwrapper.java.classpath.2=../classes/testapp.jar示例:![这里写图片描述](http://img.blog.csdn.net/20151221132546877)入口类wrapper.app.parameter.1=com.whirlpool.CloudWaher
5. 修改testapp-service
cd bin
cp sh.script.in testapp-service
APP_NAME="你的APP名字简写"APP_LONG_NAME="你的APP全名"下面加一行basedir=/home/ftpuser/testapp修改下面两句WRAPPER_CMD="$basedir/bin/wrapper"WRAPPER_CONF="$basedir/conf/wrapper.conf"chmod +x smart-service
测试
./testapp console
6.创建软链接
sudo ln -s /home/ftpuser/testapp/bin/testapp-service /etc/init.d/testapp-service
设置开机启动
/sbin/chkconfig --del testapp-service/sbin/chkconfig --add testapp-service # 保证能开机启动
启动:
/etc/init.d/testapp-service start或service testapp-service start
配置文件更多参考:
http://www.tuicool.com/articles/jqMv2q
0 0
- JAVA基础应用——java程序在centos后台运行
- centOS运行java程序以及后台运行的问题
- 让java程序在Linux后台运行
- 让java程序在Linux后台运行
- 让java程序在Linux后台运行
- Java程序后台运行
- Java 后台运行程序
- Java之——Linux后台运行jar程序
- Java之——Linux后台运行jar程序
- 在linux下利用nohup来后台运行java程序
- 在linux下利用nohup来后台运行java程序
- 在linux下利用nohup来后台运行java程序
- 在linux下利用nohup来后台运行java程序
- Java程序在Linux中实现后台运行
- Java程序在Linux中实现后台运行
- JAVA程序不能后台运行的解决方法
- LINUX下,后台运行JAVA程序
- linux系统后台运行java程序
- 【机器学习】Logistic Regression 的前世今生(理论篇)
- 【Ubuntu】安装Hadoop
- maven 为何要模块划分-聚合/继承
- 【杭电】[2004]成绩转换
- 120Triangle
- JAVA基础应用——java程序在centos后台运行
- 逆序数的三种求法
- 基于TCP协议的”hello world“
- linux线程的实现
- ffmpeg avfilter小结
- 【杭电】[1001]Sum Problem
- VBA实现数组Array与集合Collection互换
- Codevs_P3372 选学霸(并查集+DP+背包)
- Gradle Buildscript