Search code examples
javamavengoogle-app-engineweb.xml

web.xml configuration based on Maven profile


What maven plugin can be used to have the appengine-web.xml application generated based on the maven profile run, for example -Pdev or -Pprod

Example:

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>myapp-dev</application>
  <version>1</version>
  <static-files/>
  <threadsafe>true</threadsafe>
  <precompilation-enabled>false</precompilation-enabled>
</appengine-web-app>

For a -Pdev, and when the profile is -Pprod

The application name would be: <application>myapp-prod</application>


Solution

  • I use the Maven Replacer plugin and use it to replace a given String -VERSION- in my appengine-web.xml. This way I get multiple settings on Jenkins (using push to deploy) to deploy on different versions with the same code.

    It's not really fancy but gets the job done.

    <plugin>
                    <groupId>com.google.code.maven-replacer-plugin</groupId>
                    <artifactId>replacer</artifactId>
                    <version>1.5.3</version>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>replace</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <file>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/appengine-web.xml</file>
                        <token>-VERSION-</token>
                        <value>${app_version}</value>
                    </configuration>
                </plugin>