Making windows service from java class with additional libraries

484 views Asked by At

I'm using apache commons deamon to make a windows service. Making a simple service from a java class that has no libraries included works just fine. But my purpose is to make service from java class with multiple included jar libraries. I tried two things to make it but with no success. The first thing did was making --classpath (pathToClassFile);(pathToJarLibraries)/*jar ; This caused NoClassDefFoundException The second thing I did was making a runnable jar ( which includes all the libraries as executables). Running it in command prompt with java -jar (pathToJar) was ok but making it as a service leads again to NoClassDefFoundException. Could anyone tell me how to tell the prunsrv command that I have some jar libraries needed to run the main class file ?

2

There are 2 answers

0
jpmc26 On

Looks like the syntax for classpath in prunsrv is like so:

prunsrv //US//TestService --Description="Some Dummy Test Service" --Startup=auto --Classpath=%CLASSPATH%;test.jar

%CLASSPATH% is a Windows environment variable, of course, so leave it out if you don't have that environment variable.

Taken from the documentation.

0
JDJ On

If you want to create a service with a jar that has embedded jar dependencies, you have to set PR_STARTCLASS to “org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader”.