How to pass tomcat port number on command line?

16,002

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
Share:
16,002

Related videos on Youtube

Ankur
Author by

Ankur

Eclipse enthusiast Jazz RTC developer

Updated on September 15, 2022

Comments

  • Ankur
    Ankur over 1 year

    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.

  • mjs
    mjs almost 9 years
    What is the shutdown flag for?
  • Balaji Boggaram Ramanarayan
    Balaji Boggaram Ramanarayan over 8 years
    How to do with Bootstrap ?
  • lmika
    lmika almost 8 years
    Note that you may also need to set port.shutdown when shutting down the server: JAVA_OPTS="-Dport.shutdown=8005" bin/shutdown.sh.