Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Apr 2006 15:40:41 +0200
From:      Jean-Baptiste Quenot <jbq@caraldi.com>
To:        freebsd-java@freebsd.org
Subject:   Re: Getting JAVA_HOME at runtime
Message-ID:  <20060419134041.GF35777@vision.anyware>
In-Reply-To: <20060419004331.GA82761@arabica.esil.univ-mrs.fr>
References:  <20060411180145.GP53974@vision.anyware> <20060411222343.GA55418@arabica.esil.univ-mrs.fr> <20060412180028.GB29790@vision.anyware> <20060415004125.GA57315@arabica.esil.univ-mrs.fr> <20060417102456.GA37686@watt.intra.caraldi.com> <20060417184123.GA23044@misty.eyesbeyond.com> <20060418084857.GA1715@vision.anyware> <20060419004331.GA82761@arabica.esil.univ-mrs.fr>

next in thread | previous in thread | raw e-mail | index | archive | help

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

* Herve Quiroz:

> javavmwrapper,  OTOH,  uses  the  logic  from  bsd.java.mk  (not
> reimplementing it)  to pick a  port that is  *already* installed
> via the ports.

You're right,  but if it  can't read bsd.port.mk, javavm  tries to
find the JDK itself from line 465 to line 573, that's why I say we
have two implementations of the lookup algorithm.

I'm attaching a patch to add documentation to javavm, and to allow
for a  JAVAVM_DRY_RUN environment variable that  makes javavm find
the  best  suitable  JVM  and print  the  corresponding  value  of
JAVA_HOME instead of executing it.

If you are interested, I can submit a PR.

For this to  work correctly, we need javavm to  stop upon failure.
Until  now, when  the  java program  cannot  be exec-uted,  javavm
issues a warning and goes on to the next JVM.

Best regards,
-- 
     Jean-Baptiste Quenot
aka  John Banana Qwerty
http://caraldi.com/jbq/

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=20060419-freebsd-javavm

--- javavm.orig	Wed Apr 19 15:20:23 2006
+++ javavm	Wed Apr 19 15:36:01 2006
@@ -6,6 +6,24 @@
 # 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_DRY_RUN
+#
+#   When set, find the best suitable JVM and print the corresponding value of
+#   JAVA_HOME instead of executing it
+#
 # ----------------------------------------------------------------------------
 # "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
 # Maxim Sobolev <sobomax@FreeBSD.org> wrote this file.  As long as you retain
@@ -43,13 +61,19 @@
 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_DRY_RUN" ] ; 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
+            echo "${JAVA_HOME}"
+            exit 0
         fi
-        exec "${@}"
     fi
-
-    echo "${IAM}: warning: couldn't run specified Java command - \"${1}\"" >&2
 }
 
 #

--8t9RHnE3ZwKMSgU+--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060419134041.GF35777>