Is it possible to overwrite Tomcat7 ports, appBase and Realm attributes (which are in server.xml) from the startup script?

StackOverflow https://stackoverflow.com/questions/9979612

문제

In a production environment, we have many different instances of Tomcats. Each Tomcat is listening on different ports, using a different database as JDBCRealm, and running apps from a different appBase directory. So here are the parameters that have instance-specific values:

  • port attribute of Server and Connector element
  • connectionURL, connectionName, connectionPassword attributes of Realm element
  • appBase attribute of Host element

When someone (re)deploys a (new) Tomcat instance, one has to replace the server.xml (which comes from source control) to set instance-specific values to these parameters.

I would prefer to have the same server.xml in the different instances. So my question is, is it possible to overwrite/redefine these parameters from the startup script?

도움이 되었습니까?

해결책

Yes, but you'll need to parameterise your server.xml.

For example, for the http connector you'd do this:

<Connector port="${port.http}" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="${port.https}" />

and then create/edit setenv.[bat|sh] and add something along the lines of (for Windows):

set CATALINA_OPTS=-Dport.http=10180 -Dport.https=10143

Don't forget that you'll also need to parameterise the shut down port. This technique will work for any attribute value in server.xml, context.xml and web.xml.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top