簡體   English   中英

基於Maven配置文件的web.xml配置

[英]web.xml configuration based on Maven profile

可以使用什么maven插件來生成基於maven配置文件運行的appengine-web.xml應用程序,例如-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

應用程序名稱為: <application>myapp-prod</application>

您可以使用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>

我使用Maven Replacer插件並使用它來替換appengine-web.xml中的給定String -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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM