Index: /gli/trunk/gems.sh
===================================================================
--- /gli/trunk/gems.sh	(revision 17818)
+++ /gli/trunk/gems.sh	(revision 17819)
@@ -229,80 +229,105 @@
 
 
-## ---- Check Java exists ----
-javapath=
-
-# Some users may set the above line manually
-if [ "x$javapath" = "x" ]; then
-
-    # If it is set, use the JAVA_HOME environment variable
-    if [ "x$JAVA_HOME" != "x" ]; then
-	javapath="$JAVA_HOME/bin/java"
-
-    # Check if Java is on the search path
-    else
-	javapath=`which java 2> /dev/null`
-    fi
-fi
-
-# Check that a Java executable has been found
-if [ "$glilang" = "es" ]; then
-    echo "Revisando Java: $javapath"
-elif [ "$glilang" = "fr" ]; then
-    echo "Vérification de Java: $javapath"
-elif [ "$glilang" = "ru" ]; then
-    echo "ðÒÏ×ÅÒËÁ Java: $javapath"
-else
-    echo "Checking Java: $javapath"
-fi
-if [ ! -x "$javapath" ]; then
-    echo
-    if [ "$glilang" = "es" ]; then
-	echo "No se pudo localizar una versión apropiada de Java. Usted deberá "
-	echo "instalar un Ambiente de Ejecución Java (versión 1.4 o superior) "
-	echo "antes de correr la $PROGNAME."
-    elif [ "$glilang" = "fr" ]; then
-	echo "Une version adéquate de Java n'a pas pu être localisée."
-	echo "Vous devez installer un Java Runtime Environment (version 1.4 ou"
-	echo "supérieur) avant de démarrer $PROGNAME."
-    elif [ "$glilang" = "ru" ]; then
-	echo "îÅ ÕÄÁÌÏÓØ ÏÐÒÅÄÅÌÉÔØ ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÅ ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÅÊ ×ÅÒÓÉÉ Java."
-	echo "÷Ù ÄÏÌÖÎÙ ÕÓÔÁÎÏ×ÉÔØ Java Runtime Environment (×ÅÒÓÉÀ 1.4 ÉÌÉ ×ÙÛÅ)"
-	echo "ÐÅÒÅÄ ××ÏÄÏÍ $PROGNAME."
-    else
-	echo "Failed to locate an appropriate version of Java. You must install a"
-	echo "Java Runtime Environment (version 1.4 or greater) before running the"
-	echo "$PROGNAME."
-    fi
-    exit 1
-fi
-
-
-## -- Check the version of Java is new enough (1.4.0 or higher) to run the GLI --
-`$javapath -classpath . CheckJavaVersion > /dev/null`
-if [ $? -ne 2 ] ; then
-    echo
-    if [ "$glilang" = "es" ]; then
-	echo "La versión del Ambiente de Ejecución Java (JRE por sus siglas en "
-	echo "inglés) que usted tiene instalada es demasiado vieja para ejecutar "
-	echo "la $PROGNAME. Por favor instale una "
-	echo "nueva versión del Ambiente de Ejecución Java (versión 1.4 o "
-	echo "posterior) y ejecute nuevamente este guión."
-    elif [ "$glilang" = "fr" ]; then
-	echo "La version de Java Runtime Environment que vous avez installée est"
-	echo "trop vielle pour faire fonctionner $PROGNAME."
-	echo "Veuillez installer une nouvelle version du JRE (version 1.4 ou plus"
-	echo "récente) et redémarrez le script."
-    elif [ "$glilang" = "ru" ]; then
-	echo "÷ÅÒÓÉÑ Java Runtime Environment, ËÏÔÏÒÕÀ ÷Ù ÕÓÔÁÎÏ×ÉÌÉ, ÏÞÅÎØ ÓÔÁÒÁ,"
-	echo "ÞÔÏÂÙ ÕÐÒÁ×ÌÑÔØ $PROGNAME. ðÏÖÁÌÕÊÓÔÁ, "
-	echo "ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ JRE (×ÅÒÓÉÀ 1.4 ÉÌÉ ÂÏÌÅÅ ÎÏ×ÕÀ) É"
-	echo "ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ"
-    else
-	echo "The version of the Java Runtime Environment you have installed is too"
-	echo "old to run the $PROGNAME. Please install a new"
-	echo "version of the JRE (version 1.4 or newer) and rerun this script."
-    fi
-    exit 1
-fi
+## ---- Check Java ----
+echo "Java:"
+MINIMUM_JAVA_VERSION=1.4.0_00
+
+# Some users may set this line manually
+#JAVA_HOME=
+
+if [ -z $javapath ]; then
+
+    # sus out search4j
+    if [ "$_version" -eq 2 -a -e "$GSDLHOME/bin/$GSDLOS/search4j" ]; then
+        SEARCH4J_EXECUTABLE=$GSDLHOME/bin/$GSDLOS/search4j
+    elif [ "$_version" -eq 3 -a -e "$GSDL3SRCHOME/bin/$GSDLOS/search4j" ]; then
+        SEARCH4J_EXECUTABLE=$GSDL3SRCHOME/bin/search4j
+    elif [ -e "../bin/$GSDLOS/search4j" ]; then
+        SEARCH4J_EXECUTABLE=../bin/$GSDLOS/search4j
+    elif [ -e "../bin/search4j" ]; then
+        SEARCH4J_EXECUTABLE=../bin/search4j
+    else
+        echo "Couldn't determine the location of the search4j executable"
+        echo "If you are running Greenstone2"
+        echo "   * check GSDLHOME is set"
+        echo "   * check bin/$GSDLOS/search4j exists"
+        echo "   * check bin/$GSDLOS/search4j is executable"
+        echo "If you are running Greenstone3"
+        echo "   * check GSDL3SRCHOME is set"
+        echo "   * check bin/search4j exists"
+        echo "   * check bin/search4j is executable"
+        echo "   * try running 'ant compile-search4j'"
+    fi
+
+	# Give search4j a hint to find Java depending on the platform
+	if [ $GSDLOS = linux ]; then
+		HINT=`cd ..;pwd`/packages/jre
+	elif [ $GSDLOS = darwin ]; then
+		HINT=/System/Library/Frameworks/JavaVM.framework/Home
+	fi	
+	
+    javapath=`$SEARCH4J_EXECUTABLE -e -p $HINT -m $MINIMUM_JAVA_VERSION`
+
+    if [ "$?" != "0" ]; then
+
+        OLDVER=`"$SEARCH4J_EXECUTABLE" -v -p "$HINT"`
+
+        if [ "$?" = "0" ]; then
+
+            if [ "$glilang" = "es" ]; then
+                echo "La versión del Ambiente de Ejecución Java (JRE por sus siglas en "
+                echo "inglés) que usted tiene instalada es demasiado vieja para ejecutar "
+                echo "la Interfaz de la $PROGNAME. Por favor instale "
+                echo "una nueva versión del Ambiente de Ejecución Java (versión $MINIMUM_JAVA_VERSION o "
+                echo "posterior) y ejecute nuevamente este guión."
+            elif [ "$glilang" = "fr" ]; then
+                echo "La version de Java Runtime Environment que vous avez installée est"
+                echo "trop vielle pour faire fonctionner $PROGNAME."
+                echo "Veuillez installer une nouvelle version du JRE (version $MINIMUM_JAVA_VERSION ou plus"
+                echo "récente) et redémarrez le script."
+            elif [ "$glilang" = "ru" ]; then
+                echo "÷ÅÒÓÉÑ Java Runtime Environment, ËÏÔÏÒÕÀ ÷Ù ÕÓÔÁÎÏ×ÉÌÉ, ÏÞÅÎØ ÓÔÁÒÁ,"
+                echo "ÞÔÏÂÙ ÕÐÒÁ×ÌÑÔØ ÂÉÂÌÉÏÔÅÞÎÙÍ $PROGNAME. ðÏÖÁÌÕÊÓÔÁ, "
+                echo "ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ JRE (×ÅÒÓÉÀ $MINIMUM_JAVA_VERSION ÉÌÉ ÂÏÌÅÅ ÎÏ×ÕÀ) É"
+                echo "ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ"
+            else
+                echo "The version of the Java Runtime Environment you have installed ($OLDVER)"
+                echo "is too old to run the $PROGNAME. Please install a new"
+                echo "version of the JRE (version $MINIMUM_JAVA_VERSION or newer) and rerun this script."
+            fi
+            exit 1
+
+        else
+
+            echo
+            if [ "$glilang" = "es" ]; then
+                echo "No se pudo localizar una versión apropiada de Java. Usted deberá "
+                echo "instalar un Ambiente de Ejecución Java (versión $MINIMUM_JAVA_VERSION o superior) "
+                echo "antes de correr la Interfaz de la $PROGNAME."
+            elif [ "$glilang" = "fr" ]; then
+                echo "Une version adéquate de Java n'a pas pu être localisée."
+                echo "Vous devez installer un Java Runtime Environment (version $MINIMUM_JAVA_VERSION ou"
+                echo "supérieur) avant de démarrer $PROGNAME."
+				echo "Si vous avez Java installé sur votre ordinateur veuillez vérifier la variable"
+				echo "d'environnement JAVA_HOME."
+            elif [ "$glilang" = "ru" ]; then
+                echo "îÅ ÕÄÁÌÏÓØ ÏÐÒÅÄÅÌÉÔØ ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÅ ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÅÊ ×ÅÒÓÉÉ Java."
+                echo "÷Ù ÄÏÌÖÎÙ ÕÓÔÁÎÏ×ÉÔØ Java Runtime Environment (×ÅÒÓÉÀ $MINIMUM_JAVA_VERSION ÉÌÉ ×ÙÛÅ)"
+                echo "ÐÅÒÅÄ ××ÏÄÏÍ ÂÉÂÌÉÏÔÅÞÎÏÇÏ $PROGNAME."
+            else
+                echo "Failed to locate an appropriate version of Java. You must install a"
+                echo "Java Runtime Environment (version $MINIMUM_JAVA_VERSION or greater) before running the"
+                echo "$PROGNAME."
+				echo "If you have Java intalled on your machine please set the environment variable JAVA_HOME."
+            fi
+        fi
+
+    fi
+
+fi
+echo $javapath
+echo
+
+
 
 ## ---- Check that the GEMS has been compiled ----
Index: /gli/trunk/gli.sh
===================================================================
--- /gli/trunk/gli.sh	(revision 17818)
+++ /gli/trunk/gli.sh	(revision 17819)
@@ -275,5 +275,5 @@
 
 # Some users may set this line manually
-#JAVA_HOME=""
+#JAVA_HOME=
 
 if [ -z $javapath ]; then
@@ -299,20 +299,4 @@
         echo "   * check bin/search4j is executable"
         echo "   * try running 'ant compile-search4j'"
-
-        # last-resort tricks
-#        if [ -e "../packages/jre" ]; then
-#            function search4j_shell_function() {
-#              echo `cd ../packages/jre/bin; pwd`/java
-#            }
-#            SEARCH4J_EXECUTABLE=search4j_shell_function
-#        elif [ "$JAVA_HOME" != "" ]; then
-#            function search4j_shell_function() {
-#              echo $JAVA_HOME/bin/java
-#            }
-#            SEARCH4J_EXECUTABLE=search4j_shell_function
-#        else
-#            exit 1
-#        fi
-
     fi
 
