1

I've tried setting a username in tomcat-users.xml with combination of variable expansion and JAVA_OPTS. However, it does not seem to work as it would for server.xml. Is there a simple way to achieve this?

I saw an example using confd, but feel like there should be a simpler, cleaner solution.

tomcat-users.xml:

<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
    <role rolename="manager-status"/>
    <user name="${USERNAME}_foo" password="" roles="manager-status"/>
</tomcat-users>

JAVA_OPTS:

JAVA_OPTS ="-DUSERNAME=${USERNAME}"
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Dawn555
  • 85
  • 1
  • 1
  • 12
  • 1
    What operating system are you using? You put a space ` ` between `JAVA_OPTS` and the equal sign `=`. Anyway I would rather use the [Java system property `${user.name}`](https://stackoverflow.com/q/797549/11748454), which does not depend on the operating system. – Piotr P. Karwasz Apr 09 '21 at 05:32

1 Answers1

1

Try JAVA_OPTS this way

"JAVA_OPTS=-DUSERNAME=${USERNAME}"