【问题标题】:web.xml configuration based on Maven profile基于 Maven 配置文件的 web.xml 配置
【发布时间】:2015-05-31 11:07:03
【问题描述】:

什么maven插件可以用来让appengine-web.xml应用基于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>

对于-Pdev,当个人资料为-Pprod时

应用程序名称将是:&lt;application&gt;myapp-prod&lt;/application&gt;

【问题讨论】:

  • 我认为您应该选择正确的答案之一。两者都可以接受

标签: java maven google-app-engine web.xml


【解决方案1】:

我使用Maven Replacer plugin 并用它来替换我的appengine-web.xml 中的给定字符串-VERSION-。这样我就可以在 Jenkins 上获得多个设置(使用推送部署)以使用相同的代码部署在不同的版本上。

这不是很花哨,但可以完成工作。

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

【讨论】:

    【解决方案2】:

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

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

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

    这是你需要的 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>
    

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

    【讨论】:

    • 这曾经在我的情况下工作,但现在我更新了所有工具:构建后“target\generated-sources\appengine-endpoints\WEB-INF\appengine-web.xml”仍然包含 $ {appengine.app}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2011-07-22
    • 2018-09-16
    • 2012-11-30
    相关资源
    最近更新 更多