0

我正在使用 Java+Spring+FreeMarker 创建网络应用程序,并且我想将应用程序版本直接写入 FreeMarker 模板。我尝试使用 maven replacer 插件,但是,当我创建 war 包时,带有替换字符串的文件(在目标目录中)被带有原始令牌的文件覆盖。这是pom.xml的引用:

<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
 <execution>
  <phase>generate-resources</phase>
  <goals>
   <goal>replace</goal>
  </goals>
 </execution>
</executions>
<configuration>
 <includes>
  <include>${basedir}\src\main\webapp\templates\include\version.ftl
  </include>
 </includes>
 <outputFile>${basedir}\target\${project.build.finalName}\templates\include\version.ftl
 </outputFile>
<replacements>
 <replacement>
  <token>version</token>
  <value>${project.build.finalName}</value>
 </replacement>
</replacements>
</configuration>
</plugin>

我做错了什么?

4

1 回答 1

0

我找到了解决方案。需要在war插件中使用prepare-package阶段:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<useCache>true</useCache>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
<version>2.6</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
于 2016-08-23T15:41:46.140 回答