4

I have a Java application which should run on a server machine in the background (the application can be started by a command without GUI). The problem is: When I log off from the server, the application gets killed. I'm looking for something similar like nohup under Linux. I found some solutions, but I'm unsure, what is the best for my situation (Windows Server 2003, Java Application run from BAT-Skript, restart after booting the machine)? What are the pros and cons of the solutions?

Community
  • 1
  • 1
Christian Ammer
  • 7,082
  • 6
  • 41
  • 98
  • 1
    Service is the right way to go. I guess you should be asking ['how do I write a Windows service in Java?'](http://stackoverflow.com/questions/68113/how-to-create-a-windows-service-from-java-app) – Rup Dec 14 '11 at 10:42
  • @Rup: I'm not the programmer of the Java application, it's a [Tool](http://www.eex.com/de/downloads/tped) I'm using. – Christian Ammer Dec 14 '11 at 10:46
  • @Christian: That doesn't matter really. I mean you don't have to modify the Java app. Just run it as service _or_ from service. – abatishchev Dec 14 '11 at 10:49

4 Answers4

3
  • Write a windows service (on Java, C# - I don't think it does matter)
  • Start the app from your service

or

abatishchev
  • 92,232
  • 78
  • 284
  • 421
  • Do you have made some experience with a specific 3d party utility, can you recommend one? After your answer I did a web search and found [ServiceEx](http://serviceex.com/) and [RunAsService](http://sourceforge.net/projects/runasservice/) – Christian Ammer Dec 14 '11 at 11:04
3

The only way in which you can get a process to run without a user being logged in is to have the process run as a windows service or at the very least called by a windows service.

ChrisBD
  • 7,801
  • 1
  • 20
  • 32
1

Just to add to above answers.

Consider using http://wrapper.tanukisoftware.com. It's rather mature and popular (in contrast to ServiceEx and RunAsService).

Vadzim
  • 21,258
  • 10
  • 119
  • 142
  • 1
    Also take a look at http://yajsw.sourceforge.net/. There is a comparison table for YAJSW, JSW, Apache Commons Daemon and Launch4J. – Vadzim Dec 15 '11 at 16:00
0

Yes, a Windows Service is definitely the way to go but there are a few things to watch out for when you run a Java application as a Windows Service. Most of them are covered in this tutorial showing how to setup a java application with our commercial run-anything-as-a-service application, AlwaysUp:

http://www.coretechnologies.com/products/AlwaysUp/Apps/RunJavaApplicationAsAService.html

Beware: You will almost surely need the "-Xrs" flag on Windows 2003 to prevent the closing-on-logoff behavior but things can get tricky if you are catching shutdown events. Let me know if that is an issue for your situation.

CoreTech
  • 2,187
  • 2
  • 16
  • 23