Getting JAVA_HOME at runtime

Herve Quiroz herve.quiroz at esil.univ-mrs.fr
Sat Apr 15 00:41:27 UTC 2006


On Wed, Apr 12, 2006 at 08:00:28PM +0200, Jean-Baptiste Quenot wrote:
> > So indeed, JAVA_HOME is set accordingly to the JVM picked up by the
> > script.
> > 
> > That's how the launcher shell script works for devel/maven2 for example.
> 
> OK, but imagine that the target application has a shell script
> that needs JAVA_HOME.  There are plenty of programs that are based
> on JAVA_HOME instead of the java binary.
> 
> How to get the preferred JAVA_HOME?

ATM you can't. So far, each time I needed such feature I found a
workaround or ended up enforcing a JDK in the shell script.

Depending on the script you have in mind, such feature could indeed be
interesting to implement. The main problem I see here is that javavm
cannot tell which JVM is the good one until it manages to run one. So
the only way to be sure of our JAVA_HOME would be to run a Java class
that uses System.getEnv() to display JAVA_HOME to the standard output.
This would just double the startup time of the application. Anyway, if
this JAVA_HOME is important to determine, and when dealing with a
"server" application which is run once in a while (e.g. at boot), I can
imagine it could be worth it.

Herve


More information about the freebsd-java mailing list