Thursday, May 20, 2010

How to create windows service from Java application

It is relatively easy with Java Service Wrapper. It is described with JBoss example at http://wrapper.tanukisoftware.org/doc/english/integrate-simple-win.html. But actually it is even easier, so I'll try to describe it here.

Let's assume there is some ready application with public static void main method in my.company.Application class.

First, you will need to download Wrapper from here. Unpack it to some folder, better in C:/ or some short folder, I had some problems with running it from deep folder hierarchy.

Second, you will need to update configuration file at "conf/wrapper.conf". Actually, it is quite long (mostly because of comments), but worth checking as it contains mostly necessary information. You will have to update:

# path to java
wrapper.java.command=java
# this is service launcher, leave it as is
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# jars related to wrapper
wrapper.java.classpath.1=../lib/wrappertest.jar
wrapper.java.classpath.2=../lib/wrapper.jar
# all jars related to your application
wrapper.java.classpath.3=../mylib/jetty-continuation-7.0.1.v20091125.jar
wrapper.java.classpath.4=../mylib/jetty-http-7.0.1.v20091125.jar
...
# your application class that contains main method
wrapper.app.parameter.1=my.company.Application
# all parameters, when needed
wrapper.app.parameter.2=param1
wrapper.app.parameter.3=param2
...


Update other parameters if needed, but better at least check them. There is valuable and handy stuff like service name and description.

Third, run bin/InstallTestWrapper-NT.bat.

You service is installed and ready. You can start it from Administrative tools or with bin/StartTestWrapper-NT.bat.

No comments:

Post a Comment