Index: /gsdl/trunk/findjava.bat
===================================================================
--- /gsdl/trunk/findjava.bat	(revision 20391)
+++ /gsdl/trunk/findjava.bat	(revision 20391)
@@ -0,0 +1,91 @@
+@echo off
+
+:: Environment Variables passed in: _VERSION, GLILANG and 
+:: possibly also GSDLHOME and/or GSDL3SRCHOME.
+:: As a result of executing this script, the JAVA_EXECUTABLE variable 
+:: will be set, but only if Perl was found.
+
+:findJava
+
+:: We will already be in the correct folder (GLI folder), which would
+:: contain a compiled up search4j.exe if this GLI is part of an installation.
+:: If search4j.exe is not there, then it means this is an SVN checkout. 
+:: In such a case, it's up to the user checking things out to ensure JAVA_HOME
+:: is set and moreover points to the correct version of the Java.
+
+set DISPLAY_MIN_VERSION=1.4
+set MIN_VERSION=1.4.0_00
+set SEARCH4J_EXECUTABLE=search4j.exe
+if exist %SEARCH4J_EXECUTABLE% goto setJexec
+if "%_VERSION%" == "" goto tryJava
+	:: else we look for a compiled version of search4j in a GS installation
+	if "%_VERSION%" == "2" (
+		set SEARCH4J_EXECUTABLE=%GSDLHOME%\bin\windows\search4j.exe
+		set HINT=%GSDLHOME%\packages\jre
+	)
+    	if "%_VERSION%" == "3" (
+		set SEARCH4J_EXECUTABLE=%GSDL3SRCHOME%\bin\search4j.exe
+		set HINT=%GSDL3SRCHOME%\packages\jre
+	)
+	if not exist "%SEARCH4J_EXECUTABLE%" goto tryJava
+
+:setJexec    
+    "%SEARCH4J_EXECUTABLE%" -e -m "%MIN_VERSION%" -p "%HINT%" | winutil\setvar.exe JAVA_EXECUTABLE > %TMP%\set_java_executable.bat
+    call "%TMP%\set_java_executable.bat"
+    del "%TMP%\set_java_executable.bat"
+    
+    if "%JAVA_EXECUTABLE%" == "" goto noJava
+    echo Java:
+    echo %JAVA_EXECUTABLE%
+    echo.
+
+:: found java, JAVA_EXECUTABLE env var set, can exit this script
+    goto exit
+
+:tryJava
+if "%JAVA_HOME%" == "" goto noJava
+if not exist "%JAVA_HOME%\bin\java.exe" goto noJava
+	if "%GLILANG%" == "en" (
+		echo.
+		echo ***************************************************************************
+    		echo WARNING: 
+		echo Found a JAVA_HOME at %JAVA_HOME%. Attempting to use this.
+		echo However, you need to have a Java %DISPLAY_MIN_VERSION% or higher installed.
+		echo ***************************************************************************
+		echo.
+	)
+	:: Try to use this version
+	set JAVA_EXECUTABLE=%JAVA_HOME%\bin\java
+	goto exit
+
+:noJava
+    echo.
+    if "%GLILANG%" == "en" (
+		echo Failed to locate an appropriate version of Java. You must install a
+    		echo Java Runtime Environment ^(version %DISPLAY_MIN_VERSION% or greater^) before running the
+    		echo Greenstone Librarian Interface.
+	)
+
+    if "%GLILANG%" == "es" (
+		echo No se pudo localizar una versi¢n apropiada de Java. Usted deber 
+    		echo instalar un Ambiente de Ejecuci¢n Java ^(versi¢n %DISPLAY_MIN_VERSION% o superior^)
+    		echo antes de correr la Interfaz de la Biblioteca Digital Greenstone.
+	)
+
+    if "%GLILANG%" == "fr" (
+		echo Une version ad?quate de Java n'a pas pu ?tre localis?e. Vous devez
+    		echo installer un Java Runtime Environment ^(version %DISPLAY_MIN_VERSION% ou sup?rieur^)
+    		echo avant de d?marrer Greenstone Librarian Interface.
+	)
+
+    if "%GLILANG%" == "ru" (
+		echo ¥ ã «®áì ®¯à¥¥«âì ¬¥áâ®­ å®¥­¥ á®®â¢¥âáâ¢ãîé¥© ¢¥àá Java.
+    		echo ?ë ®«­ë ãáâ ­®¢âì Java Runtime Environment ^(¢¥àáî %DISPLAY_MIN_VERSION% « ¢ëè¥^) ¯¥à¥ ¢¢®®¬
+    		echo ¡¡«®â¥ç­®£® ­â¥àä¥©á  Greenstone.
+	)
+    goto exit
+
+:exit
+set SEARCH4J_EXECUTABLE=
+set MIN_VERSION=
+set DISPLAY_MIN_VERSION=
Index: /gsdl/trunk/gs2-server.bat
===================================================================
--- /gsdl/trunk/gs2-server.bat	(revision 20391)
+++ /gsdl/trunk/gs2-server.bat	(revision 20391)
@@ -0,0 +1,139 @@
+@echo off
+SETLOCAL
+
+set serverlang=en
+set java_min_version=1.4.0_00
+set PROGNAME="gs2-server"
+pushd "%CD%"
+CD /D "%~dp0"
+
+echo Greenstone 2 Server
+echo Copyright (C) 2009, New Zealand Digital Library Project, University Of Waikato
+echo This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
+echo This is free software, and you are welcome to redistribute it
+
+::  -------- Run the Greenstone 2 Server --------
+
+::  ---- Determine GSDLHOME ----
+set gsdl2path=
+
+:: Some users may set the above line manually
+if "%gsdl2path%" == "" (
+   set GSDLHOME=%CD%
+   set gsdl2path=%CD%
+)
+echo GS2 Home: %GSDLHOME%
+
+::goto autoset_gsdl_home %gsdl2path%
+
+:: Setup Greenstone2, unless it has already been done
+if "%GSDLHOME%" == "" (
+   pushd "%GSDLHOME%"
+   call setup.bat
+   popd
+)
+
+
+:: First test that there is actually something that can be run...
+:: Exit if the apache-httpd folder doesn't exist for some reason
+:: (The errors reported when the apache webserver does not exist 
+:: in the correct location are not at all helpful).
+
+:: "You cannot use the if command to test directly for a directory, but
+:: the null (NUL) device does exist in every directory. As a result, you
+:: can test for the null device to determine whether a directory exists."
+::echo %GSDLHOME%\apache-httpd\nul
+if not exist %GSDLHOME%\apache-httpd\nul (
+    echo.
+    echo UNABLE TO CONTINUE: There is no apache-httpd directory.
+    echo It does not look like the local apache webserver has been installed.
+    echo Exiting...
+    echo.
+    goto exit
+)
+:: exit 1
+
+
+:: If there's no llssite.cfg file, copy from the template
+if exist "%GSDLHOME%\llssite.cfg" goto cfgfile
+if exist "%GSDLHOME%\llssite.cfg.in" (
+   copy "%GSDLHOME%\llssite.cfg.in" "%GSDLHOME%\llssite.cfg"
+) else (
+   echo Warning: could not find llssite.cfg.in to create llssite.cfg from.
+)
+
+:cfgfile
+::  ---- Determine GSDLHOME ----
+:: JRE_HOME or JAVA_HOME must be set correctly to run this program
+bin\windows\search4j -m %java_min_version% > nul
+echo.
+:: In Java code, '...getResourceAsStream("build.properties")'
+:: needs up to be in the right directory when run
+if %ERRORLEVEL% equ 0 pushd %GSDL2PATH%
+
+:: http://ss64.com/nt/call.html (and leave in trailing slash)
+call :isinpath %GSDLHOME%\lib\java
+
+:: After the call, we come back here
+goto chkjava
+
+:isinpath
+:: http://ss64.com/nt/syntax-args.html
+ECHO Param 1: %1
+ECHO Full path of param 1: %~f1
+set mypath=%~f1
+echo.
+
+:: Does not work: http://ss64.com/nt/syntax-replace.html,
+:: section "Finding items within the PATH environment variable"
+
+:: Instead, we expand the filepath of parameter 1 to its full path and
+:: try to subtract it from the classpath. 
+call set test_cpath=%%CLASSPATH:%~f1=%%
+ECHO Test_cpath: %test_cpath%& echo.
+ECHO classpath: %CLASSPATH%& echo.
+
+:: If there IS a difference in the classpath before and after,
+:: then the filepath was already on the classpath
+if not "%CLASSPATH%" == "%test_cpath%" (
+   echo   - CLASSPATH already correct
+   echo %CLASSPATH%
+   goto :eof
+)
+
+:: If there was NO difference in the classpath before and after,
+:: then the filepath needs to be added to the classpath
+set CLASSPATH=%GSDLHOME%\lib\java;%CLASSPATH%
+
+:: http://ss64.com/nt/for_r.html and http://ss64.com/nt/for.html
+:: http://ss64.com/nt/syntax-args.html
+FOR /R "%GSDLHOME%\lib\java" %%G IN (*.jar) DO call :putinpath %%G
+echo   - Adjusted CLASSPATH
+echo.
+::echo CLASSPATH:& echo %CLASSPATH%
+goto :eof
+
+
+:putinpath
+echo jarfile: %1
+set CLASSPATH=%CLASSPATH%;%1
+goto :eof
+
+:: ---- Check Java ----
+:chkjava
+:: call the script with source, so that we have the variables it sets ($javapath)
+set exit_status=0
+:: Need to find Java. If found, JAVA_EXECUTABLE will be set
+:: call findjava.bat %serverlang% %PROGNAME%
+call findjava.bat
+if "%JAVA_EXECUTABLE%" == "" echo **** No Java executable found& goto exit
+
+
+:: ---- Run the Greenstone Server Interface ----
+echo.
+"%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" %*
+goto exit
+
+:exit
+popd
+ENDLOCAL
