JasCav
JasCav

Reputation: 34632

Run Java application as a service

I would like to run a Java application as a service. Unfortunately, I am limited in that I can't use something like the Java Service Wrapper (which does appear to be an excellent tool).

Is there any way of running an executable JAR, as a service, without relying on external applications? I currently have the service installed, but it fails to start. This is where I am getting stuck and I haven't been able to find anything on Google other than information about the JSW.

Upvotes: 24

Views: 43989

Answers (8)

Anthony O.
Anthony O.

Reputation: 24367

You can use NSSM like this:

nssm install MyService "%JAVA_HOME%\bin\java.exe" -jar "path\to\the\file.jar"

Upvotes: 3

cpierceworld
cpierceworld

Reputation: 186

Another option, Apache Commons Daemon's procrun.

See http://commons.apache.org/daemon/

Upvotes: 11

JSmooth can do it, and it is scriptable with ant.

Upvotes: 0

toba303
toba303

Reputation: 93

The most simple way I found was RunAsService.

A co-worker recommended a tool called SC, but I did not try it.

Upvotes: 0

Peter Smith
Peter Smith

Reputation: 753

one more option winrun4j. the license is eclipse's CPL.

Upvotes: 1

ykaganovich
ykaganovich

Reputation: 14964

There's an LGPL clone of the Java Service Wrapper: http://yajsw.sourceforge.net

BTW, IANAL, but I suspect that JSW people are spreading FUD, and their software can be used to service-enable commercial applications under GPL license, just like one can gzip a commercial app for redistribution. I could be completely wrong about this, though :)

Upvotes: 13

Wolfgang
Wolfgang

Reputation: 3490

A program that should run as windows service must provide certain functions that the windows service manager uses to communicate with that service.

As long as there is no JVM that implements this functions directly (and I know of none) you will need some kind of wrapper.

I have successfully used srvany for a java based windows service (Basically it allows to run any program as windows service and it works fine with java)

Upvotes: 6

dustmachine
dustmachine

Reputation: 10814

I haven't tried it (yet), but Launch4j looks like it could suit your needs.

Upvotes: 2

Related Questions