当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
怎样利用Jsvc把Java程序嵌入到Linux服务中
发布时间:2010/1/4 17:10:49 来源:www.xue.net 编辑:城市总裁吧
  在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()方法不能少,服务在启动时会先调用init(String[] args)方法
  然后调用start()方法,在服务停止是会首先调用stop()方法,然后调用destroy() 方法.
  3.把这个类打包成testjsvc.jar 放到/test目录下
  4.编写启动服务的脚本 myjsvc
  #!/bin/sh
  # myjsvc This shell script takes care of starting and stopping
  #
  # chkconfig: - 60 50
  # description: tlstat stat is a stat data daemon.
  # processname: myjsvc
  # Source function library.
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved