5

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Arpit
  • 6,212
  • 8
  • 38
  • 69
  • In the antrun configuration you posted you actually use `value="${display}"` and not `value="${displayVersion}"`, is it a typo in the original code or a cut'n'paste issue? – skuro Mar 17 '11 at 14:28
  • Its a typo... my Bad. I have edited the question to rectify the same – Arpit Mar 17 '11 at 14:30

2 Answers2

7

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>
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    Aaron, I am aware about the Maven resource filtering. But I am migrating from AMT to MAVEN and the token I use is @ -- **@version@** and I believe for Maven Resource filtering I need to change it to **${version}** Now, there are a lot of files in which I need to replace this token, and I can't go and make it **${version}**. Is there any way by which I can filter **@version@** with Maven Resource Filtering – Arpit Mar 17 '11 at 15:09
  • Try Sean's solution. Which IDE are you using? In Eclipse, you can do a global search'n'replace over all files. – Aaron Digulla Mar 17 '11 at 16:42