Getting JAVA_HOME at runtime

Jean-Baptiste Quenot jbq at caraldi.com
Wed Apr 19 13:49:06 UTC 2006


This one will still be better.
-- 
     Jean-Baptiste Quenot
aka  John Banana Qwerty
http://caraldi.com/jbq/
-------------- next part --------------
--- javavm.orig	Wed Apr 19 15:20:23 2006
+++ javavm	Wed Apr 19 15:48:54 2006
@@ -6,6 +6,30 @@
 # They can then be selected from based on environment variables and the
 # configuration file.
 #
+# Environment variables affecting the behaviour of this program:
+#
+#
+# JAVA_HOME
+#
+#   Allows to choose the preferred JVM
+#
+#
+# JAVA_VERSION
+#
+#   Allows to choose a preferred JVM version
+#
+#
+# JAVAVM_PRINT_JAVA_HOME
+#
+#   When set, find the best suitable JVM and print the corresponding value of
+#   JAVA_HOME instead of executing the java program
+#
+#
+# JAVAVM_PRINT_JAVA_PROGRAM
+#
+#   When set, find the best suitable JVM and print the path of the Java program
+#   instead of executing it
+#
 # ----------------------------------------------------------------------------
 # "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
 # Maxim Sobolev <sobomax at FreeBSD.org> wrote this file.  As long as you retain
@@ -43,13 +67,23 @@
 tryJavaCommand () {
     # Check for the command being executable and exec it if so.
     if [ -x "${1}" ]; then
-        if [ ! -z "${SAVE_PATH}" ]; then
-            export PATH=${SAVE_PATH}
+        if [ -z "$JAVAVM_PRINT_JAVA_HOME" -a -z "$JAVAVM_PRINT_JAVA_PROGRAM" ] ; then
+            if [ ! -z "${SAVE_PATH}" ]; then
+                export PATH=${SAVE_PATH}
+            fi
+
+            exec "${@}"
+            echo "${IAM}: error: couldn't run specified Java command - \"${1}\"" >&2
+            exit 1
+        else
+            if [ -n "$JAVAVM_PRINT_JAVA_HOME" ] ; then
+                echo "${JAVA_HOME}"
+            else
+                echo "${@}"
+            fi
+            exit 0
         fi
-        exec "${@}"
     fi
-
-    echo "${IAM}: warning: couldn't run specified Java command - \"${1}\"" >&2
 }
 
 #


More information about the freebsd-java mailing list