background image

Java 源码:利用 Jsvc 把 Java 程序嵌入到 Linux 服务

中去

在 linux 上以服务的方式启动 java 程序
  1.安装 jsvc
  在 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
  2.编写服务启动类
  package com.sohu.jsvc.test;
  public class TestJsvc {
  public static void main(String args[]) {
  System.out.println("execute main method!");
  }
  public void init() throws Exception {
  System.out.println("execute init method!");
  }
  public void init(String[] args) throws Exception{
  System.out.println("execute init(args) method");
  }
  public void start() throws Exception {
  System.out.println("execute start method!");
  }
  public void stop() throws Exception {
  System.out.println("execute stop method!");
  }
  public void destroy() throws Exception{
  System.out.println("execute destroy method!");
  }
  }

  main 方法可以去掉,但是 init(String[] args),start(),stop(),destroy()方法不能少,