29

Java process control is notoriously bad - primarily due to inadequate support by the Java VM/JDK classes (e.g. java.lang.Process).

I am wondering, are there any good open source libraries out there that are reliable.

The requirements would be:

  1. OSS
  2. Start/Stop processes
  3. Manage STDIN and STDOUT
  4. cross platform (at least Linux, Windows, Solaris, HP, and IBM in that order)
  5. (optional) restartable
  6. (desirable) mature
Jonik
  • 80,077
  • 70
  • 264
  • 372
Taylor Gautier
  • 4,916
  • 7
  • 30
  • 24
  • I'd add a process dependency notion as a requirement: A process/service should only start if its dependent process/service has started. If a process/service gets stopped, all of its dependent processes/services get stopped. – Max Spring Jan 23 '14 at 19:41
  • It is now 2015. I wonder if anything has changed and the answer to this question now would be different. – wilx Jan 21 '15 at 09:34
  • It's now 2020 and looks like ther're not many alternatives to java Process API. – XZen May 28 '20 at 13:36
  • There is a library on maven and github called jProcesses that is very good and powerful and cross platform. – Michael Sims Oct 23 '21 at 11:38

3 Answers3

15

How about Apache Commons Exec?

Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • 2
    Good tip - good tutorial, too! http://commons.apache.org/exec/tutorial.html – grrussel Aug 03 '11 at 21:42
  • 1
    I don't think Apache Commons Exec provides the same abstraction level as the Java Service Wrapper. For implementing a process/daemon manager Commons Exec might be a good start. – Max Spring Jan 23 '14 at 19:38
5

Java Service Wrapper might be what you're looking for. It's cross-platform, can be used to start things as a Windows service, capture IO, and generally completely manage any java app. It's very light weight and well designed. Atlassian uses it to wrap their products (Jira, Bamboo, etc), so it's battle tested.

Trenton
  • 11,678
  • 10
  • 56
  • 60
  • 3
    for service management it's fine. but it's hardly a library that can be used for easy process control. also, it's not quite OSS. – Omry Yadan Aug 24 '09 at 16:25
  • @Omry JSW has a very good process control library (http://wrapper.tanukisoftware.com/doc/english/child-exec.html), the problem is that it isn't OSS. – jnorris Aug 27 '10 at 22:32
5

One more requirement... cross platform support for killing of an orphaned process. With java.lang.Process (and Apache Commons Exec), there is no way to kill external processes when the Java application does a hard stop (kill -9). I'd really like to find a library that can handle the problem better.

One solution may be to store PIDs in some resource on disk, and then kill the processes on restart of the Java application. Of course, this would be platform dependent, so good a cross platform library would be fantastic.

Vikdor
  • 23,934
  • 10
  • 61
  • 84
Ryan
  • 51
  • 1
  • 1