23

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.

palacsint
  • 26,486
  • 10
  • 75
  • 100
JasCav
  • 33,714
  • 19
  • 103
  • 163
  • Refers to http://stackoverflow.com/questions/68113/how-to-create-a-windows-service-from-java-app – skaffman Sep 10 '09 at 17:01
  • Why can't you use Java Service Wrapper? – Kevin Sep 10 '09 at 17:23
  • @Kevin - A few different reasons. First, and foremost, is licensing (GPL - I can't open source the code that this is being applied to). – JasCav Sep 10 '09 at 17:45
  • Jason, can you use an older version of JSW before they switched the licensing? I don't believe that they retroactively changed the licensing on older versions – Kevin Sep 10 '09 at 18:46
  • 1
    Based on the wording on http://wrapper.tanukisoftware.com/doc/english/licenseCommunity.html it is very clear that the Community Edition cannot be used with a non-Open Source program. – Thorbjørn Ravn Andersen Oct 11 '10 at 09:43
  • [This question](http://stackoverflow.com/q/415409/535203) and [this question](http://stackoverflow.com/q/22931661/535203) should help too – Anthony O. May 24 '16 at 14:14

8 Answers8

13

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 :)

ykaganovich
  • 13,997
  • 7
  • 55
  • 90
  • 1
    Based on the wording on wrapper.tanukisoftware.com/doc/english/licenseCommunity.html it is very clear that the Community Edition cannot be used with a non-Open Source program due to it being under the GPL. – Thorbjørn Ravn Andersen Oct 11 '10 at 09:43
  • GPL does not preclude non-Open Source programs from being used "with" GPL programs (e.g. it's perfectly fine to run commercial applications on Linux OS). It only precludes creating a derivative work by linking against GPL code and releasing it under non-GPL license. In this case, It's not clear to me that a derivative work is being created. – ykaganovich Oct 11 '10 at 22:50
  • Meh, you might be right. They distribute their stuff not under GPL, but under some weird license that requires distributed product software to be distributed under GPL regardless of it being a derivative product. I wonder if this is legal... but I guess it's best to assume that it is. – ykaganovich Oct 12 '10 at 02:30
11

Another option, Apache Commons Daemon's procrun.

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

Reto Höhener
  • 3,910
  • 4
  • 28
  • 54
cpierceworld
  • 176
  • 1
  • 4
6

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)

Wolfgang
  • 3,420
  • 3
  • 25
  • 36
  • This is the only answer that answers the question; all the others mention yet another external tool that the OP is looking to avoid. Thanks! – mrtumnus Feb 22 '17 at 22:32
2

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

dustmachine
  • 9,903
  • 5
  • 23
  • 28
  • 2
    Doesn't register as a service but its a nice option for packaging user programs that don't run as a service. – djangofan Jul 18 '11 at 20:56
2

You can use NSSM like this:

nssm install MyService "%JAVA_HOME%\bin\java.exe" -jar "path\to\the\file.jar"
Anthony O.
  • 16,644
  • 12
  • 92
  • 151
1

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

Peter Smith
  • 713
  • 6
  • 7
  • yes, but like the other service wrappers, requires that you implement the public interface in order to integrate your app into the service handler. – djangofan Jul 18 '11 at 20:59
0

The most simple way I found was RunAsService.

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

toba303
  • 93
  • 1
  • 5
0

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

Thorbjørn Ravn Andersen
  • 68,906
  • 28
  • 171
  • 323