Java 基于Maven profile的web.xml配置

Java 基于Maven profile的web.xml配置,java,maven,google-app-engine,web.xml,Java,Maven,Google App Engine,Web.xml,什么maven插件可用于根据maven配置文件运行生成应用程序,例如-Pdev或-Pprod 示例: <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>myapp-dev</application> <version>1</version> <static-files/> <threadsafe>

什么maven插件可用于根据maven配置文件运行生成应用程序,例如
-Pdev
-Pprod

示例:

<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>

myapp开发
1.
真的
假的
对于
-Pdev
,当配置文件为
-Pprod


应用程序名称为:
myappprod

您可以使用maven war插件更改应用程序的版本和名称

在appengine-web.xml上,写在下面几行

<application>${appengine.app}</application>
<version>${version.number.gae}</version>
${appengine.app}
${version.number.gae}
这就是你需要的maven插件

<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>

org.apache.maven.plugins
maven战争插件
${project.basedir}/src/main/webapp
${project.build.directory}/${project.artifactId}
src/main/resources/application.properties
src/main/webapp/WEB-INF/appengine-WEB.xml
src/main/webapp
真的
**/appengine-web.xml
**/web.xml
开放图/**
css/**,flash/**,mobile/**,图像/**,声音/**,channel.html
和maven简介

<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>

发展
我的gae dev
1.
戳
我的gae prod
1.
我使用并使用它替换appengine-web.xml中给定的字符串-VERSION-。通过这种方式,我在Jenkins上获得了多个设置(使用push-to-deploy)以在具有相同代码的不同版本上部署

这不是很花哨,但能完成任务

<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>

com.google.code.maven-replacer-plugin
替代者
1.5.3
准备包装
代替
${project.build.directory}/generated sources/appengine endpoints/WEB-INF/appengine-WEB.xml
-版本-
${app_version}

我认为您应该选择一个正确答案。这两个都是可以接受的。在我的例子中,这曾经是有效的,但是现在我更新了所有的工具:在构建之后,“target\generated sources\appengine endpoints\WEB-INF\appengine WEB.xml”仍然包含${appengine.app}