+3  A: 

You need a java service wrapper, here is a very good one... tanuki
I mean to say, you don't need to reinvent the wheel, there are tools out there..

Teja Kantamneni
+1 for using a solution that already exists
gareth_bowles
Sorry cannot use, incompatible license.
GregB
A: 

The daemon function on my machine (old RedHat) does not return until the executed program returns. So you are going to need to have your little utility script do the forking.

Try writing your utility like this:

#!/bin/bash

(
    until java -Xms256m -Xmx768m -jar MyApp.jar; do
        echo "MyApp crashed with exit code $?.  Respawning... " >&2
        sleep 5
    done
) &

How this works. Putting a command in parentheses starts code running in a new process. You put the process in the background so the original process will return without waiting for it.

R Samuel Klatchko