Tomcat 7/8: reusing environment variables in server.xml

for some projects with tomcat, we highlight some configurations (URLs, etc.) in the environment variables.

Example: / usr / share / tomcat 7 / conf / other-urls.xml

<!-- LDAP --> <Environment name="remote/com/mycompany/ldap" type="java.lang.String" value="ldaps://myldap.mycompany.net"/> 

server.xml

  <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE server-xml [ <!ENTITY Other-URLs SYSTEM "/usr/share/tomcat7/conf/other-urls.xml"> ]> <Server port="8005" shutdown="SHUTDOWN"> ... <GlobalNamingResources> &Other-URLs; </GlobalNamingResources> .... <Service name="Catalina"> .... <Engine name="Catalina" defaultHost="localhost" jvmRoute="4996b9646dc"> <Realm className="org.apache.catalina.realm.JNDIRealm" connectionURL="${remote/com/mycompany/ldap}" userPattern="(|(uid={0},ou=People,dc=mycompany,dc=net)(uid={0},ou=Other,dc=mycompany,dc=net))" .... /> 

...

This configuration does not work (javax.naming.NamingException: cannot parse URL: $ {remote / com / mycompany / ldap}). When I write the correct LDAP URL in connectionURL, it works. I try differently: With $ {..}, without, with java: / env / comp, without.

Is there a way to reuse the environment variable in server.xml?

Thanks for any hint.

Ciao Peter Schutt

+6
source share
1 answer

Instead of solving this via XML, you can try to do this using the system properties ( -Dname=value ). There is an article that explains this in more detail .

+1
source

Source: https://habr.com/ru/post/984942/


All Articles