| Java开发windows/linux/web服务 | |
| 大狗熊 | //windows 服务 测试通过 package jServ; public class Main public static void main(String[] args) class Service implements Runnable |
| 楼主 创建:08-08-26 11:12:35 更新:08-08-26 14:59:03 | |
| 发表回复 | |
| 1/1(共1页) | |
| 大狗熊 | 在linux上以服务的方式启动java程序 -- 未测试
在tomcat的bin目录下有一个jsvc.tar.gz的文件,进入tomcat的bin目录下 #tar xvfz jsvc.tar.gz #cd jsvc-src #sh support/buildconf.sh #chmod 755 configure #./configure --with-java=/usr/local/java (改成你的JDK的位置) #make
package com.sohu.jsvc.test; public class TestJsvc { public static void main(String args[]) { public void init() throws Exception { public void init(String[] args) throws Exception{ public void start() throws Exception { public void stop() throws Exception { public void destroy() throws Exception{ }
然后调用start()方法,在服务停止是会首先调用stop()方法,然后调用destroy() 方法.
#!/bin/sh # myjsvc This shell script takes care of starting and stopping # Source function library. RETVAL=0 # jdk的安装目录 # for multi instances adapt those lines. #程序运行是所需的jar包,commons-daemon.jar是不能少的 case "$1" in stop) *)
6. #chmod -c 777 /etc/init.d/myjsvc 7. 添加服务 #chkconfig --add myjsvc #chkconfig --level 345 myjsvc on
#service myjsvc start 你可以从/test/log/myjsvc.out文件里看到如下信息: execute init(args) method execute start method
你会发现/test/log/myjsvc.out文件里会增加如下信息 execute stop method execute destroy method
|
| 1楼 创建:08-08-26 14:59:18 更新:08-08-26 14:59:18 | |
| 发表回复 | |