Maven Antrun插件中的替换任务 [英] Replace task in Maven Antrun Plugin
问题描述
我在我的Maven构建中使用antrun插件将某些JSP文件中的令牌 @version @ 替换为应用程序版本. 这就是我正在做的:
I am using antrun plugin in my maven build to replace a token @version@ in some of the JSP files with the application version. This is what I am doing:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<echo>${displayVersion}</echo>
<replace file="src/main/webapp/admin/decorators/default.jsp" token="@version@" value="${displayVersion}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
我正在将 displayVersion 作为参数传递给Maven
I am passing displayVersion as a parameter to maven
mvn clean install -DdisplayVersion="Version-1.1"
这是 Antrun插件
[INFO] [antrun:run {execution: default}]
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
main:
[echo] 9.4_70
[INFO] Executed tasks
尽管该属性已正确回显,但在我的JSP中并未替换该属性. @version @ 令牌由 {displayVersion} 代替,而不是其实际值.
Although the property is being echoed properly, it's not substituted in my JSP. The @version@ token is replaced by {displayVersion} and not it's actual value.
推荐答案
Use Maven Resources Filtering as Aaron suggested and set the delimiters in the Maven Resource Plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<delimiters>
<!-- enable maven's standard delimiters -->
<delimiter>${*}</delimiter>
<!-- enable your @delimiters@ -->
<delimiter>@</delimiter>
</delimiters>
</configuration>
</plugin>
这篇关于Maven Antrun插件中的替换任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!