Home > Java > javaTutorial > body text

java war maven obfuscation css/js class encryption

高洛峰
Release: 2016-11-22 13:37:24
Original
2247 people have browsed it

网上找了一堆 不用浪费时间了 看官方网站 或者去google搜索 不知道怎么google的去百度 老D 不得不说外国的月亮比较圆 底下的解决方案不是全部只能打包jar 没有混淆 

   <!-- ProGuard混淆插件 -->
            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>

                <version>2.0.11</version>

                <executions>
                    <execution>
                        <!-- 混淆时刻,这里是打包的时候混淆 -->
                        <phase>prepare-package</phase>
                        <goals>
                            <!-- 使用插件的什么功能,当然是混淆 -->
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- 是否将生成的PG文件安装部署 -->
                    <attach>true</attach>
                    <!-- 是否混淆 -->
                    <obfuscate>true</obfuscate>
                    <!-- 指定生成文件分类 -->
                    <attachArtifactClassifier>pg</attachArtifactClassifier>
                    <options>
                        <!-- JDK目标版本1.7 -->
                        <option>-target 1.7</option>
                        <!-- 不做压缩(删除注释、未被引用代码) -->
                        <option>-dontshrink</option>
                        <!-- 不做优化(变更代码实现逻辑) -->
                        <option>-dontoptimize</option>
                        <!-- 不跳过非公用类文件及成员 -->
                        <option>-dontskipnonpubliclibraryclasses</option>
                        <option>-dontskipnonpubliclibraryclassmembers</option>
                        <!-- 优化时允许访问并修改有修饰符的类和类的成员 -->
                        <option>-allowaccessmodification</option>
                        <!-- 使用独特的混淆类的成员名称来增加混淆 -->
                        <option>-useuniqueclassmembernames</option>
                        <!-- 不混淆所有包名,本人测试混淆后WEB项目问题实在太多,毕竟Spring配置中有大量固定写法的包名 -->
                        <option>-keeppackagenames</option>
                        <!-- 不混淆所有特殊的类 -->
                        <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod</option>
                        <!-- 不混淆所有的set/get方法,毕竟项目中使用的部分第三方框架(例如Shiro)会用到大量的set/get映射 -->
                        <!-- 这一句会薄报错 -->
                        <!-- <option>-keepclassmembers public class * {void set*(***);***get*();}</option> -->

                        <!-- 不混淆测试包下的所有类名,且类中的方法也不混淆,但是属性混淆 -->
                        <!-- <option>-keep class com.jikexueyuancrm.test.** { &lt;methods&gt;; -->
                        <!-- }</option> -->

                        <!-- 以下因为大部分是Spring管理的Bean,不对包类的类名进行混淆,但对类中的属性和方法混淆 -->
                        <option>-keep class cn.com..front.web.**</option>
                        <option>-keep class cn.com..front.service.**</option>


                        <!-- 不混淆model包中的所有类以及类的属性及方法,实体包,混淆了会导致ORM框架及前端无法识别 -->
                        <option>-keep class cn.com..front.filter.** {*;}</option>
                        <option>-keep class cn.com..base.** {*;}</option>
                        <option>-keep class cn.com..front.dao.** {*;}</option>
                        <option>-keep class cn.com..front.utils.** {*;}</option>
                        <option>-keep class cn.com..front.mybatis.** {*;}</option>
                        <option>-keep class cn.com..front.dto.** {*;}</option>
                        <option>-keep class cn.com..job.** {*;}</option>
                        <option>-keep class cn.com..pay.** {*;}</option>
                        <option>-keep class cn.com..sms.** {*;}</option>
                    </options>
                    <outjar>classes</outjar>
                    <!-- 添加依赖,这里你可以按你的需要修改,这里测试只需要一个JRE的Runtime包就行了 -->
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jsse.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>
                    </libs>
                    <!-- 对什么东西进行加载,这里仅有classes,毕竟你也不可能对配置文件及JSP混淆吧 -->
                    <injar>classes</injar>
                    <!-- 输出目录 -->
                    <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
            </plugin>
Copy after login
      <plugin>
                <groupId>com.samaxes.maven</groupId>
                <artifactId>minify-maven-plugin</artifactId>
                <version>1.7.5</version>

                <executions>
                    <execution>
                        <id>assets-minify</id>
                        <phase>process-resources</phase>
                        <configuration>
                            <!-- css -->
                            <cssEngine>YUI</cssEngine>
                            <cssSourceDir>assets</cssSourceDir>
                            <cssSourceIncludes>
                                <cssSourceInclude>styles/**/**.css</cssSourceInclude>
                            </cssSourceIncludes>
                            <!-- <cssSourceExcludes> <cssSourceExclude>vendors/**.css</cssSourceExclude> 
                                </cssSourceExcludes> -->
                            <!-- js -->
                            <jsEngine>CLOSURE</jsEngine>
                            <jsSourceDir>assets</jsSourceDir>
                            <jsSourceIncludes>
                                <jsSourceInclude>scripts/**/**.js</jsSourceInclude>
                            </jsSourceIncludes>
                            <!-- <jsSourceExcludes> <jsSourceExclude>vendors/**/*.min.js</jsSourceExclude> 
                                </jsSourceExcludes> -->
                            <!-- others -->
                            <skipMerge>true</skipMerge>
                            <nosuffix>true</nosuffix>
                            <verbose>false</verbose>
                        </configuration>
                        <goals>
                            <goal>minify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceExcludes>assets/styles/**/**.css,assets/scripts/**/**.js</warSourceExcludes>
                    <warName>${project.artifactId}</warName>
                </configuration>
            </plugin>
        </plugins>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template