0

I'm working on some open-source project and wouldn't like to keep URL of production servers in public repository with source code, but at the same time I'd like to have an opportunity to deploy using tomcat-maven-plugin.

I tried to move server url from pom.xml to settings.xml, but it didn't work. Could You please give me a hint, what is the best way to keep url out of pom.xml?

Thank You very much.

Here is my configuration: settings.xml

<settings>
    <servers>
        <server>
            <id>prod</id>
            <username>deployer</username>
            <password>********</password>
        </server>
    </servers>
</settings>

pom.xml (in the project)

<project>
    ...
    <profiles>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <server>prod</server>
                            <url>http://host:XXXX/manager/text</url>
                            <path>/</path>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Update: Yes, there is an opportunity to keep this in .properties-files, but:

  1. It's a bit strange to keep server configuration in several places, i.e. ~/.m2/settings.xml, application.properties, pom.xml. As long as username and password are able to be stored in settings.xml, it would be nice to keep server URL also there.
  2. Actually I couldn't make it work, so I'm keep working on this way as workaround...

Update 2: Just found out, why the approach with reading properties didn't work for me. I used:

mvn tomcat7:redeploy

to deploy application, and properties-maven-plugin didn't inject properties in the placeholders in tomcat7-maven-plugin configuration. After I changed tomcat7-maven-plugin execution due to deploy phase, then the injection of properties works properly by invocation:

mvn clean deploy

But never the less, I would like to know, is it possible to keep server URL in settings.xml?

Sunny
  • 83
  • 1
  • 7
  • 1
    Possible duplicate of [Reading properties file from Maven POM file](http://stackoverflow.com/questions/7144620/reading-properties-file-from-maven-pom-file) – potame Mar 25 '17 at 09:25
  • why move it to settings.xml ??? – davidxxx Mar 25 '17 at 09:34
  • @davidxxx if You mean why I want to move it to settings.xml instead of application.properties, then I just updated post. If You mean, why I wouldn't like to keep it in pom.xml - because it's a security vulnerability to keep addresses of your production servers in the source code repository, even in private repositories, what to speak about public repositories. – Sunny Mar 25 '17 at 12:48

1 Answers1

0

It is not possible to keep server URL in settings.xml, according to the specs.

What you could do is set the server name on the command line as a parameter:

mvn clean tomcat7:deploy -Drelease.server="http://host:XXXX"

And in pom.xml you can refer to the parameter like this

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <update>true</update>
                <url>${release.server}/manager/text</url>
                <server>MyServer</server>
                <path>/</path>
            </configuration>
        </plugin>
boes
  • 2,835
  • 2
  • 23
  • 28