Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass tomcat port number on command line?

Tags:

tomcat

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.

like image 543
Ankur Avatar asked Mar 21 '13 18:03

Ankur


1 Answers

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
like image 171
maksim_khokhlov Avatar answered Oct 21 '22 09:10

maksim_khokhlov