1

I am using the tomcat7-maven-plugin to deploy my application to Tomcat. In my pom.xml I currently have the following information

 <plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.2</version>
   <configuration>
      <server>test</server>
      <path>/api</path>
      <update>true</update>
      <url>http://XXX.XXX.XX.XX:8080/manager/text</url>
   </configuration>
 </plugin>

And in ~/.m2/settings.xml I have the following

<settings>
  <servers>
    <server>
      <id>test</id>
      <username>*******</username>
      <password>*******</password>
    </server>

    <server>
      <id>production</id>
      <username>*********</username>
      <password>*********</password>
    </server>
  </servers>
</settings>

My hope is to be able to be able to include selection of the server by ID as part of my command line, e.g.

mvn tomcat7:redeploy -Dserver=production

and have appropriate configuration information from the settings.xml file be used. In addition to selecting the specific username and password for deployment, this would also mean moving the URL out of the pom.xml into a separate location.

This post talks about storing the server URL outside of the POM, and seems to indicates there's a way to do this part using some properties files, but doesn't expand on where those files should be located, nor how to specify them on the command line.

Is it possible to do what I'm looking for? Or am I stuck editing the pom.xml file each time that I want to choose a different server to deploy to?

ryanmcfall
  • 585
  • 1
  • 6
  • 20

1 Answers1

3

An alternative to keeping your server ids (and credentials) in the ~/.m2/settings.xml is to make the server url a parameter in your pom.xml:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.2</version>
     <configuration>
         <url>${deploy.server}</url>             
     </configuration>
<plugin>

And then, when you run the deploy goal, you specify the url of the server you want to use:

mvn tomcat7:deploy -Ddeploy.server="http://prod.example.com:8080/manager/text" -Dtomcat.username=sfalken -Dtomcat.password=JOSHUA
tngio
  • 61
  • 6
  • Good solution to not store credentials in the pom.xml (which might be checked in version control) – Terel Feb 06 '21 at 20:05