The ports Tomcat uses are set on startup from the server.xml file, if you want to change ports you have to restart Tomcat. Why would you want to change ports dynamically? You can have multiple instances of Tomcat running on the same machine if you assign them different ports.
As William said, you can use multiple tomcat installed and one of them can work as load balancer. You can use module JK connector for this purpose.
Joined: Mar 27, 2006
Thanks William and Kalpesh!
Actually, I want to start Tomcat using a script. Before starting tomcat in a port, I want to check whether someother application or someother tomcat itself is running on that port. If some application is running on that port, I can start Tomcat in a different free port.
So, is there a way to dynamically set Tomcat port, before starting it?
Thanks and regards, Jaffer.
Author and all-around good cowpoke
Joined: Mar 22, 2000
As I said already, Tomcat sets ports based on the contents of server.xml - you could certainly re-write server.xml with revised port numbers before starting Tomcat. Bill