问题
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>
I am passing displayVersion as a parameter to maven
mvn clean install -DdisplayVersion="Version-1.1"
And this is the console output for Antrun Plugin
[INFO] [antrun:run {execution: default}]
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
main:
[echo] 9.4_70
[INFO] Executed tasks
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.
回答1:
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>
回答2:
The Maven resources plugin can replace variables in resources; so if you deliver the JSP (instead of compiling it with the jspc plugin), you can simply let the resource plugin do the work while it copies resources by enabling filtering.
来源:https://stackoverflow.com/questions/5340361/replace-task-in-maven-antrun-plugin