Maven - <server/> in settings.xml

Viewed 50237

I use tomcat-maven-plugin to deploy my war to a server. What I have to do is configure it like this in my pom.xml:

<configuration>
...
   <url>http://localhost/manager</url>
   <username>admin</username>
   <password>admin</password>
...
</configuration>

But then I obviously want to keep this settings in a different place since I work on my computer but then there's a staging and a live server as well where the settings of the server are different.

So let's use the .m2/settings.xml:

<servers>
    <server>
        <id>local_tomcat</id>
        <username>admin</username>
        <password>admin</password>
    </server>
</servers>

Now change the pom.xml:

<configuration>
    <server>local_tomcat</server>
</configuration>

But where to put the URL of the server? There's no place for that in the settings.xml under the server tag! Maybe like this?

<profiles>
  <profile>
     <id>tomcat-config</id>
      <properties>
    <tomcat.url>http://localhost/manager</tomcat.url>
      </properties>
  </profile>
</profiles>

<activeProfiles>
   <activeProfile>tomcat-config</activeProfile>
</activeProfiles>

..and use the ${tomcat.url} property.

But then the question is, why use the server tag in settings.xml at all? Why not use properties for the username and password as well? Or is there a place for the URL as well in the settings URL so I don't have to use properties?

2 Answers

settings.xml

<settings>
  <servers>
    <server>
        <id>company.jfrog.io</id>
        <username>user-name</username>
        <password>user-password</password>
    </server>   
  </servers>
</settings>

pom.xml

<repositories>
    <repository>
        <id>company.jfrog.io</id>
        <url>https://company.jfrog.io/company/release</url>
    </repository>
</repositories>

Put settings.xml to

c:/Users/user-name/.m2/settings.xml (for Windows),

~/.m2/settings.xml (for Linux).

company.jfrog.io can be any identifier, but it should be the same in settings.xml and pom.xml.

This works for Maven 3.

Related