Reputation: 732
I want to set environment variables via Kubernetes for server.xml in tomcat. Here is my deployment.yaml:
apiVersion: v1
kind: Pod
metadata:
name: tomcat-test-pod
...
...
env:
- name: hostName
value: 'test.com'
- name: localhost
value: 'localhost.com'
And here is my server.xml:
<?xml version='1.0' encoding='utf-8'?>
<Resource
auth="Container"
description="Global E-Mail Resource"
mail.debug="false"
mail.smtp.auth="false"
mail.smtp.ehlo="true"
mail.smtp.host="${hostName}"
mail.smtp.localhost="${localhost}"
mail.smtp.port="25"
mail.smtp.sendpartial="true"
mail.transport.protocol="smtp"
name="mail/Session"
type="javax.mail.Session"/>
From https://tomcat.apache.org/tomcat-9.0-doc/config/systemprops.html, it says that I need to set org.apache.tomcat.util.digester. PROPERTY_SOURCE
to org.apache.tomcat.util.digester.EnvironmentPropertySource
, but I am not sure what I am supposed to do. Do I need to set it in setenv.sh or do I need to create another class? Any help will be appreciated..
Upvotes: 6
Views: 6184
Reputation: 16105
org.apache.tomcat.util.digester.PROPERTY_SOURCE
is a Java system property so you can set it where system properties are accepted:
setenv.sh
:CATALINA_OPTS="$CATALINA_OPTS -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
This will work only if you call catalina.sh/startup.sh
to start Tomcat (directly or indirecly). For example it will not work on Windows, when starting Tomcat as a service.
catalina.properties
:org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
This always works.
Upvotes: 4