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