Ankur
Ankur

Reputation: 819

How to pass tomcat port number on command line?

Is it possible to tell tomcat to use a particular port instead of the one specified in server.xml? Or a way to configure an environment variable as port number in server.xml? (which I can set in a batch file which starts tomcat)

Essentially, I want to launch different copies (versions) of a tomcat instance without having to manually change the server.xml in each of them and having to remember which one would launch at which port. I wish to specify the port number when I launch it so that there is no conflict in the multiple instances.

Upvotes: 14

Views: 18498

Answers (1)

maksim_khokhlov
maksim_khokhlov

Reputation: 804

Change your server.xml so that it will use port numbers expanded from properties instead of hardcoded ones:

<Server port="${port.shutdown}" shutdown="SHUTDOWN">
...
  <Connector port="${port.http}" protocol="HTTP/1.1"/>
...
</Server>

Here's how you can start in Linux (assuming your current directory is CATALINA_HOME):

JAVA_OPTS="-Dport.shutdown=8005 -Dport.http=8080" bin/startup.sh

In windows it should be smth like following:

set "JAVA_OPTS=-Dport.shutdown=8005 -Dport.http=8080"
bin\startup.bat

Upvotes: 29

Related Questions