Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24332)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24333)
@@ -58,4 +58,5 @@
 import org.greenstone.gatherer.metadata.FilenameEncoding;
 import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
+import org.greenstone.gatherer.util.GS3ServerThread;
 import org.greenstone.gatherer.util.JarTools;
 import org.greenstone.gatherer.util.StaticStrings;
@@ -372,5 +373,5 @@
 				}
 				else {
-					GS3ServerThread thread = new GS3ServerThread(gsdl_path);
+					GS3ServerThread thread = new GS3ServerThread(gsdl_path, "start");
 					thread.start();
 				}
@@ -705,4 +706,23 @@
 		if (isGsdlRemote) {
 			remoteGreenstoneServer.exit();
+		} else if (GS3) { // stop the local tomcat web server when running GS3
+		    // can't call ant stop from its own thread - what if GLI has exited by then?
+		    // issue call to ant stop from the main GLI thread
+		    //GS3ServerThread thread = new GS3ServerThread(Configuration.gsdl_path, "stop");
+		    //thread.start();
+
+		    try {
+			String shellCommand = null;
+			Process p = null;
+			if (Utility.isWindows()) {			    
+			    p = Runtime.getRuntime().exec("cmd /C \"cd " + Configuration.gsdl_path + File.separator + ".. && ant stop\"\"");	
+			} else {
+			    p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant stop -f \"" + Configuration.gsdl_path + ".." + File.separator + "build.xml\""});
+			}
+		    } catch(Exception e) {
+			System.err.println("Exception when trying to stop the tomcat web server: " + e);
+			DebugStream.printStackTrace(e);
+		    }
+		    
 		}
 
@@ -1595,33 +1615,3 @@
 	}
 	
-	public class GS3ServerThread extends Thread
-	{
-		String _gsdl_path = "";
-		
-		public GS3ServerThread(String gsdl_path)
-		{
-			_gsdl_path = gsdl_path;
-		}
-		
-		public void run()
-		{
-			try
-			{
-				String shellCommand = null;
-				Process p = null;
-				if (Utility.isWindows())
-				{
-					p = Runtime.getRuntime().exec("cmd /C \"cd " + _gsdl_path + File.separator + ".. && ant start\"\"");	
-				}
-				else
-				{
-					p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant restart -f \"" + _gsdl_path + ".." + File.separator + "build.xml\""});
-				}
-			}
-			catch(Exception ex)
-			{
-				ex.printStackTrace();
-			}
-		}
-	}
 }
Index: /main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java	(revision 24333)
+++ /main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java	(revision 24333)
@@ -0,0 +1,79 @@
+/**
+ *#########################################################################
+ *
+ * A component of the Gatherer application, part of the Greenstone digital
+ * library suite from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * <BR><BR>
+ *
+ * Author: Sam McIntosh, Greenstone Digital Library, University of Waikato
+ *
+ * <BR><BR>
+ *
+ * Copyright (C) 2011 New Zealand Digital Library Project
+ *
+ * <BR><BR>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * <BR><BR>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * <BR><BR>
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *########################################################################
+ */
+
+package org.greenstone.gatherer.util;
+import java.io.File;
+
+/** Class for GS3, for issuing ant commands from GLI */
+public class GS3ServerThread extends Thread
+{
+    String _gsdl_path = "";
+    String _ant_command = "";
+    
+    public GS3ServerThread(String gsdl_path, String ant_command)
+    {
+	_gsdl_path = gsdl_path;
+	_ant_command = ant_command;
+    }
+    
+    public void run()
+    {
+	try
+	    {
+		String shellCommand = null;
+		Process p = null;
+		if (Utility.isWindows())
+		    {
+			if(_ant_command.indexOf("start") != -1) { // running an "ant (re)start" command on windows, run start
+			    _ant_command = "start";
+			}
+			p = Runtime.getRuntime().exec("cmd /C \"cd " + _gsdl_path + File.separator + ".. && ant " + _ant_command + "\"\"");	
+		    }
+		else
+		    {
+			if(_ant_command.indexOf("start") != -1) { // if running an "ant (re)start" command on non-Windows, run restart
+			    _ant_command = "restart";
+			}
+			p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant " + _ant_command + " -f \"" + _gsdl_path + ".." + File.separator + "build.xml\""});
+		    }
+	    }
+	catch(Exception ex)
+	    {
+		ex.printStackTrace();
+	    }
+    }
+}
