Use Jsvc to embed Java programs into Linux Services (1)

Source: Internet
Author: User
Tags gz file

Start java programs as a service in linux

1. Install jsvc

There is a jsvc.tar.gz file under the bindirectory of tomcat. Go to the bin directory of tomcat.

# Tar xvfz jsvc.tar.gz

# Cd jsvc-src

# Sh support/buildconf. sh

# Chmod 755 configure

#./Configure -- with-java =/usr/local/java (change to your JDK location)

# Make


2. Compile the Service Startup class

     
      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!");}}
     
The main method can be removed, but the init (String [] args), start (), stop (), destroy () methods cannot be fewer, when the service starts, it will first call the init (String [] args) method.

Call the start () method. when the service is stopped, the stop () method is called first, and then the destroy () method is called.

3. package this class into testjsvc. jar and put it in the/test directory.


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.