Skip to content
Advertisement

Command to change tomcat server port

I’m using ubuntu, and I’m in a need of some command, using which I can change the server port configurations.

Therefore, my question is…

Is there any linux command, to update the Tomcat server connection port, as well as server shutdown port?

Advertisement

Answer

maksim_khokhlov answer looks promising if you want to change it at the start (it is taken from here)

Basicly you have to change the config in your server.xml. But I dont think you can change the port at runtime without restarting.

Another way would be to write a script which first changes the server.xml and then starts tomcat.

for example with python

python updateserverxml.py 8888
(and in this file you replace the port and start the server.)

Or another way could be using docker and map the exposed port from your standardport to your desired port.

maksim_khokhlov answer below:

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
Advertisement