I am writing an application that uses jsvc to start a Java service as a daemon. I need to use something like jsvc , because my application uses ports under 1024, and yet I really don't want to run it as root so that the created files belong to another user. I would also like to keep dependencies and configuration to a minimum, so all client needs are the JVM and the jsvc binary.
However, it seems that jsvc has one main catch; it cannot detect the Java home folder on this Unix operating system, which is rather complicated:
$ ./startup.sh Cannot locate Java home
I managed to solve the problem on Ubuntu, at least manually, by installing the JVM home directory:
jsvc ... -home /usr/lib/jvm/default-java/ ...
Is there a way to dynamically determine the Java home directory from a Bash script so that I can do this work on most Unix / Linuxes? I could sleep better at night, doing something like:
JAVA_HOME="$( ... )" jsvc ... -home "$JAVA_HOME" ...
... rather than hard coding for each individual operating system. Is there a way that, given binary java , I can find the home directory of its JVM / JRE?
Naftuli Kay
source share