2016-08-23 53 views
0

我正在用Java + Spring + FreeMarker創建Web應用程序,並且我想直接將應用程序版本寫入FreeMarker模板中。我嘗試使用Maven替代品插件,但是,當我創建war包時,替換字符串(在目標目錄中)的文件將被包含原始標記的文件重寫。 下面是引自的pom.xmlMaven用替換的字符串覆蓋文件

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

我做錯了嗎?

回答

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>