I developed a Java program for RFID reader, the program run as a server to continuous listen to the response from readers. The program was run as console application. So, it need manually startup. This is very troublesome when deploy to commercial environment. So, I want to refactor the program as windows service.
I found Java Service Wrapper is what I need. this package to let your Java application run as windows service.
It provides three kinds of integration. You don't need to code any thing by using WrapperSimpleApp and WrapperStartStopApp. However, I prefer the third method that is implement the WrapperListener. The following section depicts the detail programming model of the using WrapperListener.
We have to do two things before the program can run as windows service.
The first thing is to code, since I choose implementation the WrapperListener interface. So the first thing to do is adding the interface code to my program with following steps.
I found Java Service Wrapper is what I need. this package to let your Java application run as windows service.
It provides three kinds of integration. You don't need to code any thing by using WrapperSimpleApp and WrapperStartStopApp. However, I prefer the third method that is implement the WrapperListener. The following section depicts the detail programming model of the using WrapperListener.
We have to do two things before the program can run as windows service.
The first thing is to code, since I choose implementation the WrapperListener interface. So the first thing to do is adding the interface code to my program with following steps.
- Add wrapper.jar into you eclipse project as reference.
- Implements interface WrapperListener
- make your class constructor to private
- Register this class to WrapperManager by the following code: WrapperManager.start( new UPortController(), args );
- Put your startup logic in public Integer start(String[] arg)
- Put your shutdown logic in public int Close(int arg0)
The second steps is setting up the wrapper environment and configuration.
The most easy way to do this is copy the directory structure from the wrapper package.
Here is my file structure.
App
|-bin (the startup bat/sh files and wrapper executable file should inside this folder)
|-lib (your jar files and wrapper.dll)
|-conf (contain only one file named wrapper.conf that described the way to load your class)
Be aware to check your Java class path setting and MANIFEST.MF in jar file.
I list my class path setting as following:
%CLASSPATH%=
.;C:\java\jre1.5.0_09\lib\rt.jar;C:\java\jre1.5.0_09\lib\jsse.jar;C:\java\jre1.5
.0_09\lib\jce.jar;
and MANIFEST.MF content in my jar file.
Manifest-Version: 1.0
Created-By: 1.5.0_09 (Sun Microsystems Inc.)
Class-Path: rt.jar activemq-all-5.0.0.jar commons-lang.jar commons-logging-1.1.jar commons-net-1.4.1.jar spring.jar wrapper.jar
Main-Class: xxx.yyy.zzz.UPortController
Reference
- http://wrapper.tanukisoftware.org/doc/english/introduction.html
沒有留言:
張貼留言