9

Currently, I have in my server.xml:

<Connector port="8080" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />

I want it to become:

<Connector port="${oms.ui.port}" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />

I put this property oms.ui.port in a property file residing in apache-tomcat-7.0.8\lib but it does not find it, I get:

WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'port' to '${oms.ui.port}' did not find a matching property.

Maybe someone with a better Tomcat experience can help me, please?

Boris Hamanov
  • 3,085
  • 9
  • 35
  • 58

1 Answers1

19

According to Tomcat 7.0 Configuration Overview:

Apache Ant-style variable substitution is supported; a system property with the name propname may be used in a configuration file using the syntax ${propname}. All system properties are available including those set using the -D syntax, those automatically made available by the JVM and those configured in the $CATALINA_BASE/conf/catalina.properties file.

So you can use either a JVM system property or catalina.properties to declare your variable and assign a value to it.

javabrett
  • 7,020
  • 4
  • 51
  • 73
  • 1
    I never knew about this until now and so traditionally, for multiple tomcat instances of a similar app, had to manually change the server.xml and context.xml files. This feature is awesome! – Volksman Nov 27 '19 at 19:41
  • You can also configure it to use system envs - see property [org.apache.tomcat.util.digester. PROPERTY_SOURCE](https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html) – user11153 Nov 19 '21 at 11:11