Index: main/trunk/greenstone3/src/java/org/greenstone/server/BaseProperty.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/BaseProperty.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/BaseProperty.java	(revision 24207)
@@ -6,4 +6,5 @@
     public final String GSDL_VERSION;
     public final String AUTOSTART;
+    public final String KEEPPORT;
     public final String START_BROWSER;
 
@@ -21,5 +22,5 @@
     public final String SERVER_SETTINGS;
     
-    protected BaseProperty(String version, String web_port, String autostart, String startbrowser) 
+    protected BaseProperty(String version, String web_port, String autostart, String startbrowser, String keepport) 
     {
 	// property names
@@ -31,4 +32,5 @@
 	AUTOSTART = autostart;
 	START_BROWSER = startbrowser;
+	KEEPPORT = keepport;
     }
 
Index: main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 24207)
@@ -21,4 +21,5 @@
 
     protected JCheckBox autoEnter;
+    protected JCheckBox keepPortToggle;
 
     protected JSpinner portNumber_spinner = null;
@@ -31,4 +32,5 @@
     protected int portNum = DEFPORT;
     protected boolean autoStart = false;
+    protected boolean keepPort = false;
     protected String browserPath = "";
     protected boolean useDefaultBrowser = true;
@@ -67,4 +69,12 @@
 	}
 
+	String keep_port_str = server.config_properties.getProperty(BaseServer.Property.KEEPPORT).trim();
+	if (keep_port_str.equals("true") || keep_port_str.equals("1")) {
+	    this.keepPort = true;
+	} else {
+	    this.keepPort = false;
+	}
+
+
 	setTitle(server.dictionary.get("ServerSettings.Title"));
 	setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@@ -76,4 +86,5 @@
 
 	autoEnter = new JCheckBox(server.dictionary.get("ServerSettings.Auto_Start"));
+	keepPortToggle = new JCheckBox(server.dictionary.get("ServerSettings.Keep_Port"));
 	
 	if (autoStart) {
@@ -83,4 +94,11 @@
 	}
 	autoEnter.setBackground(bg_color);
+
+	if(keepPort) {
+	    keepPortToggle.setSelected(true);
+	} else {
+	    keepPortToggle.setSelected(false);
+	}
+	keepPortToggle.setBackground(bg_color);
 
 
@@ -107,6 +125,7 @@
 	port_panel.setBackground(bg_color);
 
-	JPanel top_panel = new JPanel(new GridLayout(2,1));
+	JPanel top_panel = new JPanel(new GridLayout(3,1));
 	top_panel.add(port_panel);
+	top_panel.add(keepPortToggle);
 	top_panel.add(autoEnter);
 
@@ -227,4 +246,8 @@
             	has_changed = true;
 	    }
+	    if (keepPort != keepPortToggle.isSelected()) {
+            	has_changed = true;
+	    }
+
 
 	    // call subclass' onSave method, which may indicate (further) changes,
Index: main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java	(revision 24207)
@@ -26,4 +26,5 @@
 import org.greenstone.server.BaseServer;
 import org.greenstone.server.BaseProperty;
+
 
 public class Server2 extends BaseServer 
@@ -287,5 +288,5 @@
 	    suffix = httpprefix + suffix;
 	}
-	
+
 	libraryURL = "http://" + host + ":" + port + suffix;
     }
@@ -297,4 +298,6 @@
 	// first choice is port 80, second choice starts at 8282
 	String port = config_properties.getProperty("portnumber", "80");
+	String keepport = config_properties.getProperty("keepport", "0"); // default is to not try to keep the same port
+
 	int portDefault = 8282;
 	try {
@@ -302,27 +305,35 @@
 	    boolean verbose = true;
 	    if(!PortFinder.isPortAvailable(portNum, verbose)) { // first time, print any Port Unavailable messages
-		
-		PortFinder portFinder = new PortFinder(portDefault, 101);
-		// Search for a free port silently from now on--don't want more
-		// messages saying that a port could not be found...
-		portNum = portFinder.findPortInRange(!verbose);
-		
-		if (portNum == -1) {
-		    // If we've still not found a free port, do we try the default port again?
-		    System.err.println("No free port found. Going to try on " + portDefault + " anyway.");
-		    port = Integer.toString(portDefault);
+		if(keepport.equals("1")) {
+		    String errorMsg = "Unable to run the Greenstone server on port " + port + ". It may already be in use.";
+		    System.err.println("\n******************");
+		    logger_.error(errorMsg);
+		    System.err.println("If you wish to try another port, go to File > Settings of the Greenstone Server interface and either change the port number or untick the \"Do Not Modify Port\" option there. Then press the \"Enter Library\" button.");
+		    System.err.println("******************\n");
 		} else {
-		    port = Integer.toString(portNum);
-		}
-		config_properties.setProperty("portnumber", port); // store the correct port
-
-		// write this updated port to the config file, since the configure target uses the file to run
-		ScriptReadWrite scriptReadWrite = new ScriptReadWrite();
-		ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file);
-		scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port
-		scriptReadWrite.writeOutFile(config_properties_file, fileLines);
-
-		configure_required_ = true;
-		System.err.println("Running server on port " + port + ".");
+
+		    PortFinder portFinder = new PortFinder(portDefault, 101);
+		    // Search for a free port silently from now on--don't want more
+		    // messages saying that a port could not be found...
+		    portNum = portFinder.findPortInRange(!verbose);
+		    
+		    if (portNum == -1) {
+			// If we've still not found a free port, do we try the default port again?
+			System.err.println("No free port found. Going to try on " + portDefault + " anyway.");
+			port = Integer.toString(portDefault);
+		    } else {
+			port = Integer.toString(portNum);
+		    }
+		    config_properties.setProperty("portnumber", port); // store the correct port
+		    
+		    // write this updated port to the config file, since the configure target uses the file to run
+		    ScriptReadWrite scriptReadWrite = new ScriptReadWrite();
+		    ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file);
+		    scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port
+		    scriptReadWrite.writeOutFile(config_properties_file, fileLines);
+		    
+		    configure_required_ = true;
+		    System.err.println("Running server on port " + port + ".");
+		}
 	    }    
 	} catch (Exception e) {
Index: main/trunk/greenstone3/src/java/org/greenstone/server/Server2Property.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/Server2Property.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/Server2Property.java	(revision 24207)
@@ -9,5 +9,5 @@
 	// Initialising customised final variables 
 	// Version number, WEB_PORT
-	super("2", "portnumber", "autoenter", "start_browser");
+	super("2", "portnumber", "autoenter", "start_browser", "keepport");
     }
 
Index: main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java	(revision 24207)
@@ -109,4 +109,9 @@
 	    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
 	}
+	boolean keep_port = keepPortToggle.isSelected();
+	if(keepPort != keep_port) {
+	    String newKeepPort = keep_port ? "1" : "0";
+	    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort);
+	}
 
 	// external access - onSave() would have updated this value
Index: main/trunk/greenstone3/src/java/org/greenstone/server/Server3Property.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/Server3Property.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/Server3Property.java	(revision 24207)
@@ -10,5 +10,5 @@
 	// Version number, WEB_PORT, autoenter, startbrowser
 	// For GS3, the last two are controlled by the same property
-	super("3", "tomcat.port", "server.auto.start", "server.auto.start");
+	super("3", "tomcat.port", "server.auto.start", "server.auto.start", "server.keep.port");
     }
 
Index: main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java	(revision 24203)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java	(revision 24207)
@@ -93,4 +93,7 @@
 	newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
 
+	String newKeepPort = (new Boolean(keepPortToggle.isSelected())).toString();
+	newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort);
+
 	String newServletDef = (String) servlet_combobox.getSelectedItem();
 	newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.DEFAULT_SERVLET, (String) url_mappings.get(newServletDef));	
