aspose file tools*
The moose likes Tomcat and the fly likes Dynamic Setting of Server Port in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Dynamic Setting of Server Port in Tomcat" Watch "Dynamic Setting of Server Port in Tomcat" New topic
Author

Dynamic Setting of Server Port in Tomcat

Jeffies Shah
Greenhorn

Joined: Mar 27, 2006
Posts: 7
Hi,

Is it possible to set Tomcat port dynamically from a text file or a properties file? If so, how to achieve that?

Thanks and regards,
Jaffer.


"He owns Pan-Am. He owns Congress. He owns the Civil Aeronautics Board. But he does not own the sky." (Howard Hughes in 'The Aviator').
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
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.

Bill
Kalpesh Patel
Greenhorn

Joined: Mar 27, 2006
Posts: 4
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.
Jeffies Shah
Greenhorn

Joined: Mar 27, 2006
Posts: 7
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
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
 
jQuery in Action, 2nd edition
 
subject: Dynamic Setting of Server Port in Tomcat