Index: greenstone3/trunk/build.xml
===================================================================
--- greenstone3/trunk/build.xml	(revision 20051)
+++ greenstone3/trunk/build.xml	(revision 20079)
@@ -76,5 +76,12 @@
     
   <!-- version properties for external packages -->
-  <property name="tomcat.version" value="apache-tomcat-5.5.25"/>
+  <!-- for Java versions < 1.4, we print out the message that Java is too old.
+	For Java 1.4, we use Tomcat 5.5, for Java5 and higher, we use Tomcat 6.0-->
+  <condition property="tomcat.version" value="apache-tomcat-5.5.25" else="apache-tomcat-6.0.20"> 
+    <equals arg1="1.4" arg2="${ant.java.version}"/>
+  </condition>
+  <condition property="tomcat.version.major" value="5" else="6"> 
+    <equals arg1="1.4" arg2="${ant.java.version}"/>
+  </condition>
   <property name="axis.zip.version" value="axis-bin-1_2_1.zip"/>
   <property name="axis.dir.version" value="axis-1_2_1"/>
@@ -266,5 +273,28 @@
 
   -->
-
+  
+  <!-- All elements that Tomcat 5 exposes to applications -->
+  <path id="tomcat5">
+	<pathelement location="${catalina.home}/common/classes"/>
+	<fileset dir="${catalina.home}/common/endorsed">
+	  <include name="*.jar"/>
+	</fileset>
+	<fileset dir="${catalina.home}/common/lib">
+	  <include name="*.jar"/>
+	</fileset>
+	<!-- seems to be empty, but will leave in just in case some people make use of this to customise their install: -->
+	<pathelement location="${catalina.home}/shared/classes"/>
+	<fileset dir="${catalina.home}/shared/lib">
+	  <include name="*.jar"/>
+	</fileset>
+  </path>
+  
+  <!-- All elements that Tomcat 6 exposes to applications -->
+  <path id="tomcat6">
+	<fileset dir="${catalina.home}/lib">
+	  <include name="*.jar"/>
+	</fileset>
+  </path>
+  
   <path id="compile.classpath">
     <!-- Include all jar files and libraries in our jni lib directory -->
@@ -290,16 +320,7 @@
     <pathelement location="${lib.jni}/mgpp.jar"/>
     
-    <!-- Include all elements that Tomcat exposes to applications -->
-    <pathelement location="${catalina.home}/common/classes"/>
-    <fileset dir="${catalina.home}/common/endorsed">
-      <include name="*.jar"/>
-    </fileset>
-    <fileset dir="${catalina.home}/common/lib">
-      <include name="*.jar"/>
-    </fileset>
-    <pathelement location="${catalina.home}/shared/classes"/>
-    <fileset dir="${catalina.home}/shared/lib">
-      <include name="*.jar"/>
-    </fileset>
+	<!-- Include all elements that Tomcat exposes to applications -->
+	<path refid="tomcat${tomcat.version.major}"/>
+
   </path>
 
@@ -527,6 +548,12 @@
     <echo>activating xalan.jar</echo>
     <copy file="${web.lib}/xalan.jar.tmp" tofile="${web.lib}/xalan.jar"/>
-    <if><bool><isset property="current.os.ismac"/></bool>
-      <copy file="${web.lib}/xalan.jar.tmp" tofile="${catalina.home}/common/endorsed/xalan.jar"/> 
+	<if>
+	  <bool>
+		<and>
+		  <isset property="current.os.ismac"/>
+		  <available file="${catalina.home}/common/endorsed" type="dir"/>
+		</and>
+	  </bool>
+	  <copy file="${web.lib}/xalan.jar.tmp" tofile="${catalina.home}/common/endorsed/xalan.jar"/> 
     </if>
   </target>
@@ -632,5 +659,4 @@
   <!-- we download tomcat and the compat module - its needed for 1.4, and doesn't seem to harm 1.5 -->
   <target name="prepare-tomcat" depends="init,setup-proxy" if="tomcat.islocal">
-
     <if>
       <bool>
@@ -645,9 +671,16 @@
       <unzip src="${packages.home}/${tomcat.version}.zip" 
         dest="${packages.home}"/>
-      <get src="http://www.greenstone.org/gs3files/${tomcat.version}-compat.zip"
-        dest="${packages.home}/${tomcat.version}-compat.zip"
-        usetimestamp="true"/>
-      <unzip src="${packages.home}/${tomcat.version}-compat.zip" 
-        dest="${packages.home}"/>
+	
+		<!-- If we are using Java 1.4, we'd be using tomcat 5.5 in which case 
+		we would need to have the tomcat compat package to work with Java 1.4-->
+	  <if>
+		<bool><equals arg1="1.4" arg2="${ant.java.version}"/></bool>
+		  <get src="http://www.greenstone.org/gs3files/${tomcat.version}-compat.zip"
+			dest="${packages.home}/${tomcat.version}-compat.zip"
+			usetimestamp="true"/>
+		<unzip src="${packages.home}/${tomcat.version}-compat.zip" 
+			dest="${packages.home}"/>
+	  </if>
+	
       <!-- delete any existing tomcat -->
       <delete dir="${packages.home}/tomcat"/>
@@ -683,5 +716,6 @@
   <target name="configure-tomcat-local" depends="init" if="tomcat.islocal">
     <!-- re-setup the server.xml file -->
-    <copy file="${basedir}/resources/tomcat/server.xml" tofile="${packages.home}/tomcat/conf/server.xml" overwrite="true">
+    <copy file="${basedir}/resources/tomcat/server_tomcat${tomcat.version.major}.xml"
+		tofile="${packages.home}/tomcat/conf/server.xml" overwrite="true">
       <filterset>
         <filter token="port" value="${tomcat.port}"/>
@@ -797,6 +831,6 @@
   </target>
 
-  <!-- ======================= Axis Targets ============================ --> 
-
+  <!-- ======================= Axis Targets ============================ -->  
+  
   <target name="prepare-axis" depends="init">
 
@@ -984,4 +1018,11 @@
   <target name="compile-core" depends="init" 
     description="Compile only the Greenstone core">
+	<if>
+	  <!-- Rather than test for tomcat 6, testing here for NOT tomcat 5 
+		(so that it may hopefully still serve when it becomes tomcat 7) -->
+	  <bool><not><equals arg1="5" arg2="${tomcat.version.major}"/></not></bool>
+	    <copy file="${web.lib}/xercesImpl.jar" todir="${catalina.home}/lib"/>
+        <copy file="${web.lib}/xml-apis.jar" todir="${catalina.home}/lib"/>
+	</if>
     <mkdir dir="${build.home}"/>
     <javac srcdir="${src.home}"
@@ -1032,6 +1073,6 @@
     <if>
       <bool><istrue value="${tomcat.islocal}"/></bool>
-      <copy file="${packages.home}/tomcat/common/endorsed/xercesImpl.jar" todir="${web.applet}"/>
-      <copy file="${packages.home}/tomcat/common/endorsed/xml-apis.jar" todir="${web.applet}"/>
+		<copy file="${web.lib}/xercesImpl.jar" todir="${web.applet}"/>
+		<copy file="${web.lib}/xml-apis.jar" todir="${web.applet}"/>
     </if>
 
