您可以使用maven-war-plugin
的exploded
目標得到一個臨時文件夾(如target
實際上下創建的任何)什麼將在後面作最後war
文件的一部分分解的版本,然後執行對這個replacer
插件文件(一個安全的副本,與其他使用該文件的插件不衝突)。
這種做法實際上也是由official replacer plugin doc
有書面文件,具有類似配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
</configuration>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml</file>
<token>@@[email protected]@</token>
<value>local</value>
</configuration>
</plugin>
注:replacer
文件還建議使用useCache
選項,它應防止插件覆蓋以前創建的exploded
目標。但是,這個選項並不適合這個目的。
同樣,下面的方法將代替根據我的測試工作:
- 使用
maven-war-plugin
的exploded
目標target
下,共創未來戰爭文件的一個<war_name>-tmp
目錄的臨時副本:這不是一個問題,無論如何target
應該通過clean
指令無論如何被丟棄
- 配置
replacer
插件,以取代0的副本文件
- 配置使用其
webXml
選項指向web.xml
文件的最後war
文件的默認war
目標
下將適用上述方法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<!-- explode the future war content for pre-package processing -->
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
<configuration>
<webappDirectory>${project.build.directory}/${project.build.finalName}-tmp</webappDirectory>
</configuration>
</execution>
<execution>
<!-- use the same execution id to further configure the default binding and execution -->
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<!-- during the package phase, use the processed web.xml file -->
<webXml>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</webXml>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<!-- apply pre-package processing on web resources -->
<id>process-web-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</file>
<token>@@[email protected]@</token>
<value>local</value>
</configuration>
</plugin>
我已經有我的構建聲明中的'maven-war-plugin'的插件聲明。我應該修改現有的添加執行還是需要一個全新的聲明? – amphibient
你可以在同一個插件聲明中添加額外的執行器,也請注意我剛添加的最新更新的全局配置 –
我的'$ {project.build.directory}/$ {project.build.finalName}/WEB-INF/web .xml'不存在。我的'target'目錄只包含'classes','generated-sources'和'test-classes'。 IOW,我無法在目標中找到web.xml – amphibient