Search code examples
javatomcatcatalinasystem-properties

Tomcat - Overriding catalina.properties from commandline


I would like to have a property in catalina.properties and on some cases overriding it from commandline with -D=propvalue

Is this possible?

More specific, I would like to control the port of a connector in server.xml with a system property, like this:

    <Connector port="${custom.port}" sendReasonPhrase="true" maxThreads="200"/>

In catalina.properties I have the property set: custom.port=9000

I would like to keep it there, but in some cases pass an override to tomcat, like -Dcustom.port=9001.

Seems like the configuration in catalina.properties has precedence and will be used. Which is unexpected behaviour.

Is there a way to enforce it the other way around? Is there another way to have a default in server.xml, something like that:

    <Connector port="${custom.port:9000}" sendReasonPhrase="true" maxThreads="200"/>

And if the system property does not exists, it will be set to 9000.


Solution

  • Tomcat doesn't allow you to override properties defined at JVM startup to override those listed in catalina.properties.

    It would be an easy feature to add, but there might be some security and/or separation-of-duties considerations to be had. My recommendation is to file a Bugzilla enhancement request. If you provide a patch or pull request on GitHub, we'll put you in the changelog. :)