Index: /main/trunk/greenstone3/build.xml
===================================================================
--- /main/trunk/greenstone3/build.xml	(revision 30012)
+++ /main/trunk/greenstone3/build.xml	(revision 30013)
@@ -797,4 +797,17 @@
   </target>
 
+  <!-- Need a copy of the check-derby-running target with a distinct property, because ant restart runs 
+       both stop and start, which stop and start derby respectively. Both  need check the derby socket.
+       Because each property can be set only once during an invocation with ant, ant restart will need 
+       two check-derbyserver properties, one for each derby check. -->
+  <target name="check-derbyserver-started">
+    <condition property="derby.isstarted" value="true" else="false">
+      <socket server="${derby.server}" port="${derby.server.port}"/>
+    </condition>
+    <echo>Derby is running: ${derby.isstarted}</echo>
+  </target>
+
+
+  <!-- Unused -->
   <target name="start-derby-java" depends="check-derbyserver-running">
     <if><bool><not><istrue value="${derby.isrunning}"/></not></bool>
@@ -810,9 +823,17 @@
   </target>
   
+  <target name="start-derby" depends="check-derbyserver-started">
+    <if><bool><not><istrue value="${derby.isstarted}"/></not></bool>
+      <echo>About to launch derby on ${derby.server}:${derby.server.port}</echo>
+      <antcall target="force-start-derby"/>
+      <else>
+	<echo>Derby networked server ALREADY RUNNING on ${derby.server}:${derby.server.port}</echo>
+      </else>
+    </if>
+  </target>
+
   <!-- Using derby 10.1.2.1
        See db-derby-10.1.2.1-bin/docs/html/adminguide/index.html -->
-  <target name="start-derby" depends="check-derbyserver-running">
-    <if><bool><not><istrue value="${derby.isrunning}"/></not></bool>
-      <echo>About to launch derby on ${derby.server}:${derby.server.port}</echo>
+  <target name="force-start-derby">
       <property name="derby.server.classpath.prop" refid="derby.server.classpath" />
       
@@ -824,8 +845,5 @@
 	<arg value="${derby.server.port}"/>
       </exec>
-      <else>
-	<echo>Derby networked server ALREADY RUNNING on ${derby.server}:${derby.server.port}</echo>
-      </else>
-    </if>
+
   </target>
 
@@ -1514,12 +1532,19 @@
   </target>  
   
-
-  <!-- Another way: http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/ -->
-  <target name="start-tomcat" description="Startup only Tomcat" depends="init,check-tomcat-running" if="tomcat.islocal">
-    <if><bool><istrue value="${tomcat.isrunning}"/></bool>
+  <target name="start-tomcat" description="Startup only Tomcat" depends="check-tomcat-started">
+
+    <if><bool><istrue value="${tomcat.isstarted}"/></bool>
       <echo>**************************************</echo>
       <echo>A WEB SERVER IS ALREADY RUNNING ON http://${tomcat.server}:${tomcat.port}. NOT STARTING.</echo>
       <echo>**************************************</echo>
       <else>
+	<antcall target="force-start-tomcat"/>
+      </else>
+      </if>
+  </target>
+
+  <!-- Another way: http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/ -->
+  <target name="force-start-tomcat" description="Startup only Tomcat" depends="init" if="tomcat.islocal">
+
     <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
     <property name="tomcat.path" refid="local.tomcat.path"/>
@@ -1571,6 +1596,4 @@
     </waitfor>
 
-   </else>
-   </if>
   </target>
 
@@ -1622,4 +1645,15 @@
     </condition>
   </target>
+  
+  <!-- Need a copy of the check-tomcat-running target with a distinct property, because ant restart runs 
+       both stop and start, both of which need to do tomcat checks. Each property can be set only once during 
+       an invocation with ant. So ant restart will need two properties to store each of the tomcat checks -->
+  <target name="check-tomcat-started">
+    <condition property="tomcat.isstarted">
+      <http url="http://${tomcat.server}:${tomcat.port}"/>
+    </condition>
+  </target>
+
+
 
   <!-- stop-tomcat checks if the tomcat server is already running. If it appears to be running
@@ -1650,5 +1684,5 @@
   </target>
 
-  <target name="restart-tomcat" description="Shutdown and restart only Tomcat" depends="init,stop-tomcat,start-tomcat"/>
+  <target name="restart-tomcat" description="Shutdown and restart only Tomcat" depends="init,stop-tomcat,force-start-tomcat"/>
 
   <target name="setup-catalina-ant-tasks">
@@ -1844,5 +1878,5 @@
 	<istrue value="${tomcat.isrunning}"/>
 	</bool>
-      <antcall target="start-tomcat"/>
+      <antcall target="force-start-tomcat"/>
     </if>
     -->
@@ -1931,5 +1965,5 @@
   <target name="deploy-localsite" depends="init" 
     description="Deploy the SOAP server for localsite. Will start and stop Tomcat.">
-    <antcall target="start-tomcat"/>
+    <antcall target="force-start-tomcat"/>
     <echo>Deploying ${base.webservice.name} web services for localsite under service name: localsite</echo>
     <antcall target="create-deployment-files">
