web.xml configuration based on Maven profile

2019-07-20 13:54发布

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>

2条回答
We Are One
2楼-- · 2019-07-20 14:04

You can use maven-war-plugin to change version and name of your application

On appengine-web.xml, write below lines

<application>${appengine.app}</application>
<version>${version.number.gae}</version>

And this is maven plugin you need

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warSourceDirectory>${project.basedir}/src/main/webapp</warSourceDirectory>
        <webappDirectory>${project.build.directory}/${project.artifactId}</webappDirectory>
        <filters>
            <filter>src/main/resources/application.properties</filter>
            <filter>src/main/webapp/WEB-INF/appengine-web.xml</filter>
        </filters>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/appengine-web.xml</include>
                    <include>**/web.xml</include>
                    <include>open_graph/**</include>
                </includes>
            </resource>
        </webResources>

        <!-- Exclude all timestamp specific static files. (see maven-resource-plugin in this pom.xml) -->
        <warSourceExcludes>css/**,flash/**,mobile/**,images/**,<!--js/**,-->sounds/**,channel.html</warSourceExcludes>

    </configuration>
</plugin>

And maven profiles

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <appengine.app>my-gae-dev</appengine.app>
            <version.number.gae>1</version.number.gae>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <appengine.app>my-gae-prod</appengine.app>
            <version.number.gae>1</version.number.gae>
        </properties>
    </profile>
</profiles>
查看更多
不美不萌又怎样
3楼-- · 2019-07-20 14:18

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>
查看更多
登录 后发表回答