Index: greenstone3/branches/customizingGreenstone3/gs3-setup.bat
===================================================================
--- greenstone3/branches/customizingGreenstone3/gs3-setup.bat	(revision 14684)
+++ greenstone3/branches/customizingGreenstone3/gs3-setup.bat	(revision 15191)
@@ -1,3 +1,5 @@
 @echo off
+
+set java_min_version=1.4.0_00
 
 if exist gs3-setup.bat goto start
@@ -7,10 +9,8 @@
 :start
 :: ---- Set the GSDL3HOME variable to the current directory ----
-cd | winutil\setvar.exe GSDL3SRCHOME > setgsdl3.bat
-call setgsdl3.bat
-del setgsdl3.bat
-echo GSDL3SRCHOME: %GSDL3SRCHOME%
+cd | winutil\setvar.exe GSDL3SRCHOME > %SystemRoot%\Temp\setgsdl3.bat
+call %SystemRoot%\Temp\setgsdl3.bat
+del %SystemRoot%\Temp\setgsdl3.bat
 set GSDL3HOME=%GSDL3SRCHOME%\web
-echo GSDL3HOME: %GSDL3HOME%
 
 :: change if using external tomcat
@@ -19,78 +19,32 @@
 :: ---- Set other important environment variables ----
 set GSDLOS=windows
-set PATH=%PATH%;%GSDL3SRCHOME%\bin;%GSDL3SRCHOME%\bin\script;%GSDL3SRCHOME%\lib\jni;
+set ANT_HOME=%GSDL3SRCHOME%\packages\ant
+set PATH=%PATH%;%GSDL3SRCHOME%\bin;%GSDL3SRCHOME%\bin\script;%GSDL3SRCHOME%\lib\jni;%ANT_HOME%\bin
 
 :: ---- Set the CLASSPATH environment variable ----
+if "%GS_CP_SET%" == "yes" goto skipSetCp
 set CLASSPATH=.;%GSDL3HOME%\WEB-INF\classes;%GSDL3SRCHOME%\resources\java;%CLASSPATH%
-if exist setcp.bat del setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3HOME%"\WEB-INF\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\lib\jni\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%TOMCAT_HOME%"\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\build\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
+if exist %SystemRoot%\Temp\setcp.bat del %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3HOME%"\WEB-INF\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\lib\jni\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%TOMCAT_HOME%"\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\build\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+echo set GS_CP_SET=yes >> %SystemRoot%\Temp\setcp.bat
+call %SystemRoot%\Temp\setcp.bat
+del %SystemRoot%\Temp\setcp.bat
+:skipSetCp
 
-call setcp.bat
-del setcp.bat
+winutil\search4j.exe -m %java_min_version% | winutil\setvar.exe _JRE_HOME > %SystemRoot%\Temp\set_jre_home.bat
+call %SystemRoot%\Temp\set_jre_home.bat
+del %SystemRoot%\Temp\set_jre_home.bat
 
-echo CLASSPATH: %CLASSPATH%
+echo %_JRE_HOME%\bin\java.exe | winutil\setvar.exe RUNJAVA > %SystemRoot%\Temp\setrunjava.bat
+call %SystemRoot%\Temp\setrunjava.bat
+del %SystemRoot%\Temp\setrunjava.bat
 
-::cd %GSDL3HOME%
+if "%JRE_HOME%" == "" set JRE_HOME=%_JRE_HOME%
 
-:findJava
-:: ---- Check Java SDK exists ----
-set JAVAPATH=
-
-:: Some users may set the above line manually
-if not "%JAVAPATH%" == "" goto testJava
-   
-:: If it is set, use the JAVA_HOME environment variable
-    if not "%JAVA_HOME%" == "" goto javahome
-
-    :: Check if Java is on the search path
-    echo %PATH%| winutil\which.exe java.exe | winutil\setvar.exe JAVAPATH > setjava.bat
-    call setjava.bat
-    del setjava.bat
-    echo %JAVAPATH%
-    if not "%JAVAPATH%" == "" goto testJava
-
-    :: Still haven't found anything, so try looking in the registry (gulp!)
-    type nul > jdk.reg
-    regedit /E jdk.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit"
-    type jdk.reg > jdk.txt
-    del jdk.reg
-    type nul > jre.reg
-    regedit /E jre.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"
-    type jre.reg > jre.txt
-    del jre.reg
-
-    winutil\findjava.exe jdk.txt jre.txt | winutil\setvar.exe JAVAPATH > setjava.bat
-    del jdk.txt
-    del jre.txt
-    call setjava.bat
-    del setjava.bat
-
-    :: If nothing was found in the registry, we're stuck
-    if "%JAVAPATH%" == "" goto noJava
-
-    set JAVAPATH=%JAVAPATH%\bin
-    goto testJava
-
-:javahome
-    set JAVAPATH=%JAVA_HOME%\bin
-
-:testJava
-if exist "%JAVAPATH%\java.exe" goto  exit
-
-
-:noJava
-    echo.
-    echo Failed to locate an appropriate version of Java. You must install a
-    echo Java Development Kit (version 1.4 or greater) before running the
-    echo Greenstone 3 Digital Library Software.
-    pause
-    goto exit
-
-:exit
-
-
-
+echo GSDL3SRCHOME : %GSDL3SRCHOME%
+echo GSDL3HOME    : %GSDL3HOME%
+echo JAVA         : %RUNJAVA%
