Maven Replacer插件,正则表达式无法正常工作 [英] Maven replacer plugin, regex no working
问题描述
我正在与Maven进行项目合作,并使用maven-replacer-plugin将我的所有CSS/javascript文件替换为缩小版本.
I'm working on a project with Maven and using the maven-replacer-plugin to replace all my css/javascript files for the minified version.
我要替换这个:
<!-- JSMIN js/script.min.js -->
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="js/jquery.placeholder.min.js"></script>
<script src="js/smoothscroll.js" async=""></script>
<script src="js/javascript.js"></script>
<script src="js/swfobject.js"></script>
<script src="js/player.js"></script>
<!-- END JSMIN -->
与此:
<script src="js/script.js"></script>
类似于CSS.
插件说它已将正则表达式应用于我的4个html文件,这是正确的,但我看不到这些文件上的更改.
The plugin says that it has applied the regex to my 4 html files which is correct but i see no changes on those files.
这是插件的配置
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.basedir}/src/main/webapp/</basedir>
<outputDir>test</outputDir>
<includes>
<include>**/*.html</include>
</includes>
<regexFlags>
<regexFlag>CASE_INSENSITIVE</regexFlag>
<regexFlag>MULTILINE</regexFlag>
<regexFlag>DOTALL</regexFlag>
</regexFlags>
<replacements>
<replacement>
<token><!-- JSMIN (.*) -->(.*?(\r))+.*?<!-- END JSMIN --></token>
<value><script src="$1"></script></value>
</replacement>
<replacement>
<token><!-- CSSMIN (.*) -->(.*?(\r))+.*?<!-- END CSSMIN --></token>
<value><link href="$1" rel="stylesheet" type="text/css"/></value>
</replacement>
</replacements>
</configuration>
</plugin>
正则表达式对我和我的同事来说似乎是正确的...有什么帮助吗? 预先感谢
The regex seems correct to me and my co-workers...any help? Thanks in advance
推荐答案
http://code.google.com/p/maven-replacer-plugin/wiki/UsageWithOtherPlugins
在将替换文件打包到战争中之前,需要有一个挂钩来运行这些文件上的替换文件.如果两者都在同一阶段执行(即prepare-package),请确保将其添加到maven-replacer-plugin之前.确保使用2.0.1或更低版本的war插件,因为常用的2.1.0+会复制资源两次,从而覆盖替换资源.使用以下war插件配置,可以在打包文件之前对其进行修改.
There needs to be a hooking spot for running replacements on files before they are packaged into a war. Make sure you add this before the maven-replacer-plugin if they both execute in the same phase (i.e. prepare-package). Make sure you use version 2.0.1 or below of the war plugin since the commonly used 2.1.0+ copies resources twice which overrides replacements. Use the following war plugin configuration to allow the files to be modified before being packaged.
这篇关于Maven Replacer插件,正则表达式无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!