使用Maven插件不起作用的CSS和JS文件



我正在尝试在我的Spring MVC Web应用程序中使用YUI压缩机Maven插件,然后按照http://www.baeldung.com/maven-minification in of http://www.baeldung.com/maven-minification-of-js - 和CSS-Assets。我已将以下内容添加到我的pom.xml文件中:

   <plugin>
         <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
             <version>1.5.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
               <webappDirectory>${project.build.directory}/min</webappDirectory>
                <excludes>
                    <exclude>**/*.min.js</exclude>
                    <exclude>**/handlebars-3133af2.js</exclude>
                    <exclude>**/require.js</exclude>
                </excludes>
            </configuration>
    </plugin>

我在src/main/webapp下的子文件夹中有许多CS和JS文件,并且根据文档,所有这些都应缩小。但是,当我运行maven clean install时,我也不会在控制台中看到与缩小相关的任何日志,也不会在war文件中找到任何缩小文件。

我想要的是将缩小文件保存在名为min的子文件夹下,与现有CSS或JS文件相同的文件夹中的同一文件名

现在的控制台日志是:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building smartwcm-services 6.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ smartwcm-services ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 36 resources
[INFO] 
[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ smartwcm-services ---
[ERROR] E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js [1:2]: illegal character
[ERROR] ...E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js:line 1:column 2:illegal character
    /* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js [1:2]: syntax error
[ERROR] ...E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js:line 1:column 2:syntax error
    /* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js [1:3]: illegal character
[ERROR] ...E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js:line 1:column 3:illegal character
    /* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js [1:0]: Compilation produced 3 syntax errors.
[ERROR] ...E:projectssmartwcmsource-codesmartwcm-servicessrcmainwebapplayoutcommonadminv3cacsscontentdesignazure.js:line 1:column 0:Compilation produced 3 syntax errors.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.060 s
[INFO] Finished at: 2016-12-29T11:25:32+05:30
[INFO] Final Memory: 19M/111M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:yuicompressor-maven-plugin:1.5.1:compress (default) on project smartwcm-services: Execution default of goal net.alchim31.maven:yuicompressor-maven-plugin:1.5.1:compress failed: Compilation produced 3 syntax errors. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

如果您在pom.xml中没有nosuffix选项运行,就像您发布的配置一样,您将在Target min文件夹中获得模拟文件。您将在Maven

中看到下面的登录
[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ spring-static-resources ---
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] foo.js (44b) -> foo-min.js (37b)[84%]
[INFO] utils.js (48b) -> utils-min.js (28b)[58%]
[INFO] main.js (138b) -> main-min.js (100b)[72%]
[INFO] router.js (86b) -> router-min.js (64b)[74%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] foo.js (44b) -> foo-min.js (37b)[84%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] myCss.css (127343b) -> myCss-min.css (106005b)[83%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] total input (637075b) -> output (530291b)[83%]

使用<nosuffix>true</nosuffix>运行时,您将在日志下方。此选项将为您提供Target min文件夹中的缩小文件,但将保持文件名相同。

[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ spring-static-resources ---
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] foo.js (44b) -> foo.js (37b)[84%]
[INFO] utils.js (48b) -> utils.js (28b)[58%]
[INFO] main.js (138b) -> main.js (100b)[72%]
[INFO] router.js (86b) -> router.js (64b)[74%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] foo.js (44b) -> foo.js (37b)[84%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] myCss.css (127343b) -> myCss.css (106005b)[83%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] total input (637075b) -> output (530291b)[83%]

在战争中包括这些最小化的文件,而不是您需要在pom.xml中设置 <webappDirectory>的原始文件。因此,您的配置应如下

 <plugin>
         <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>${yuicompressor-maven-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
               <webappDirectory>${project.build.directory}/min</webappDirectory>
                <excludes>
                    <exclude>**/*.min.js</exclude>
                    <exclude>**/handlebars-3133af2.js</exclude>
                    <exclude>**/require.js</exclude>
                </excludes>
            </configuration>
    </plugin>

上面的日志来自github项目https://github.com/eugenp/tutorials/tree/master/master/handling-spring-spring-static-resources。在此项目中检查pom.xml是否参考。

最新更新