2

我正在使用 Maven 开发一个项目,并使用 maven-replacer-plugin 将我的所有 css/javascript 文件替换为缩小版本。

我想替换这个:

<!-- 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 文件,这是正确的,但我看不到这些文件的任何更改。

这是插件的配置

<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>&lt;!-- JSMIN (.*) --&gt;(.*?(\r))+.*?&lt;!-- END JSMIN --&gt;</token>
                <value>&lt;script src="$1"&gt;&lt;/script&gt;</value>
            </replacement>
            <replacement>
                <token>&lt;!-- CSSMIN (.*) --&gt;(.*?(\r))+.*?&lt;!-- END CSSMIN --&gt;</token>
                <value>&lt;link href="$1" rel="stylesheet" type="text/css"/&gt;</value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

正则表达式对我和我的同事来说似乎是正确的......有什么帮助吗?提前致谢

4

2 回答 2

6

http://code.google.com/p/maven-replacer-plugin/wiki/UsageWithOtherPlugins

在将文件打包到战争中之前,需要有一个挂钩点来对文件进行替换。如果它们都在同一阶段(即准备包)执行,请确保在 maven-replacer-plugin 之前添加它。确保您使用 2.0.1 或更低版本的 war 插件,因为常用的 2.1.0+ 会复制资源两次,这会覆盖替换。使用以下 war 插件配置允许在打包之前修改文件。

于 2012-10-30T10:54:53.020 回答
0

我已将您的代码复制粘贴到一个测试 pom 中,它工作正常。

你确定你检查了正确的文件吗?更新的文件位于 /src/main/webapp/test

M。

于 2012-07-19T10:36:23.830 回答