直接上代码

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>geexek_demo</groupId>
<artifactId>geexek_demo</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<build>
<!-- 利用yuicompressor-maven-plugin 插件,当打包项目时,自动压缩文件 -->
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 压缩文件编码 -->
<encoding>GBK</encoding>
<!-- 排除已压缩的文件,例如jquery-1.8.2.min.js -->
<excludes>
<exclude>**/**.min.js</exclude>
</excludes>
<!-- 不使用后缀 -->
<nosuffix>true</nosuffix>
<!-- 把文件压缩成一行 -->
<linebreakpos>-1</linebreakpos>
<!-- 指定需要压缩文件的目录,这是我的目录(修改为你自己的目录吧..) -->
<sourceDirectory>${basedir}/assets</sourceDirectory>
</configuration>
</plugin>
</plugins>
<resources>
<!-- 直接复制不用压缩的文件,图片,已经压缩的css,js -->
<resource>
<directory>${basedir}/assets</directory>
<includes>
<include>**/**.min.js</include>
<include>**/images/**</include>
</includes>
</resource>
</resources>
</build>
</project>

配置好后,运行mvn clean package ,就可以把想压缩的静态文件,成功压缩!!