Allow java/javavmwrapper to report the location of the JVM

Jean-Baptiste Quenot jbq at caraldi.com
Wed Apr 19 15:45:46 UTC 2006


>Submitter-Id:	current-users
>Originator:	Jean-Baptiste Quenot
>Confidential:	no
>Synopsis:	Allow java/javavmwrapper to report the location of the JVM
>Severity:	non-critical
>Priority:	medium
>Category:	ports
>Class:		update
>Release:	FreeBSD 5.5-PRERELEASE i386
>Environment:
System: FreeBSD vision.anyware 5.5-PRERELEASE FreeBSD 5.5-PRERELEASE #1: Thu Mar 9 19:20:53 CET 2006 jbq at vision.anyware:/usr/obj/usr/src/sys/VISION i386
>Description:
Please see discussion at
http://lists.freebsd.org/pipermail/freebsd-java/2006-April/005152.html

The Java ports infrastructure provides ${JAVA_HOME} and ${JAVA} on build-time to
a port's Makefile, but it would be great to set the Java version requirement on
a per-port basis in the rc flags.  This requires to get JAVA_HOME and java
executable path from javavmwrapper at runtime.

The idea is to make javavm recognize two special environment variables:

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

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.

Thanks in advance!
>Fix:
diff -ru javavmwrapper.orig/src/javavm.1 javavmwrapper/src/javavm.1
--- javavmwrapper.orig/src/javavm.1	Tue Apr 19 00:03:27 2005
+++ javavmwrapper/src/javavm.1	Wed Apr 19 17:32:22 2006
@@ -124,6 +124,12 @@
 .Ql 1.5
 and
 .Ql 1.5+ .
+.It Ev 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.
+.It Ev JAVAVM_PRINT_JAVA_PROGRAM
+When set, find the best suitable JVM and print the path of the Java program
+instead of executing it.
 .El
 .Sh FILES
 .Bl -tag -width indent
diff -ru javavmwrapper.orig/src/javavmwrapper.sh javavmwrapper/src/javavmwrapper.sh
--- javavmwrapper.orig/src/javavmwrapper.sh	Fri Nov  4 00:04:40 2005
+++ javavmwrapper/src/javavmwrapper.sh	Wed Apr 19 17:29:22 2006
@@ -6,6 +6,8 @@
 # They can then be selected from based on environment variables and the
 # configuration file.
 #
+# Please have a look at the javavm(1) man page for more information.
+#
 # ----------------------------------------------------------------------------
 # "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 +45,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