Tomcat-users.xml is rewritten on container restart - how do I supply credentials?

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

  •  30-07-2021
  •  | 
  •  

Question

Im using cargo to deploy a war file to a tomcat server. I'm unable to login to the manager however as conf/tomcat-users.xml is rewritten when I start the container ie

mvn cargo:run

how I can supply user/password creds to access the manager?

cheers!

Edit: Cargo configuration

<plugins>
    <!-- Start's the plugin tag for Cargo! -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
  <wait>false</wait>
  <container>
    <containerId>tomcat${tomcat.major}x</containerId>
    <zipUrlInstaller>
      <url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
      <extractDir>${project.build.directory}/extract/</extractDir>
      <downloadDir>${project.build.directory}/download/</downloadDir>
    </zipUrlInstaller>
    <output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
    <log>${project.build.directory}/cargo.log</log>
  </container>
  <configuration>
    <home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
    <properties>
      <cargo.logging>high</cargo.logging>
      <cargo.servlet.port>9080</cargo.servlet.port>
      <cargo.tomcat.ajp.port>9008</cargo.tomcat.ajp.port>
    </properties>
  </configuration>
</configuration>
<executions>
  <execution>
    <id>start-container</id>
    <phase>pre-integration-test</phase>
    <goals>
      <goal>start</goal>
      <goal>deploy</goal>
    </goals>
    <configuration>
      <deployer>
        <deployables>
          <deployable>
            <groupId>${project.groupId}</groupId>
            <artifactId>mod-war</artifactId>
            <type>war</type>
            <pingURL>http://localhost:9080/mod-war</pingURL>
            <pingTimeout>30000</pingTimeout>
            <properties>
              <context>mod-war</context>
            </properties>
          </deployable>
        </deployables>
      </deployer>
    </configuration>
  </execution>
  <execution>
    <id>stop-container</id>
    <phase>post-integration-test</phase>
    <goals>
      <goal>stop</goal>
    </goals>
  </execution>
</executions>

Was it helpful?

Solution

Found it. You can supply custom configuration through the following xml (link to cargo docs in the above comments)

      <files>
        <copy>
          <file>tomcat-users.xml</file>
          <tofile>conf/tomcat-users.xml</tofile>
          <configfile>true</configfile>
          <overwrite>true</overwrite>
        </copy>
      </files>

So you can specify your own conf/*.xml or anything else and it will be copied before the container starts. I can login to the manager now :)

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top