替换 Maven Antrun 插件中的任务
我在我的 Maven 构建中使用 antrun 插件来用应用程序版本替换一些 JSP 文件中的标记 @version@ 。 这就是我正在做的:
<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
mvn clean install -DdisplayVersion="Version-1.1"
这是 displayVersion 的控制台输出>Antrun Plugin
[INFO] [antrun:run {execution: default}]
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
main:
[echo] 9.4_70
[INFO] Executed tasks
尽管该属性已正确回显,但它在我的 JSP 中并未被替换。 @version@ 令牌被 {displayVersion} 替换,而不是它的实际值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照 Aaron 建议使用 Maven 资源过滤,并在 Maven 中设置分隔符资源插件:
Use Maven Resources Filtering as Aaron suggested and set the delimiters in the Maven Resource Plugin:
Maven资源插件可以替换资源中的变量;因此,如果您交付 JSP(而不是使用 jspc 插件编译它),您可以简单地让资源插件在通过 启用过滤。
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.