Home Java javaTutorial java war maven obfuscation css/js class encryption

java war maven obfuscation css/js class encryption

Nov 22, 2016 pm 01:37 PM

网上找了一堆 不用浪费时间了 看官方网站 或者去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


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

What is the difference between memory leaks in Java programs on ARM and x86 architecture CPUs? What is the difference between memory leaks in Java programs on ARM and x86 architecture CPUs? Apr 19, 2025 pm 11:18 PM

Analysis of memory leak phenomenon of Java programs on different architecture CPUs. This article will discuss a case where a Java program exhibits different memory behaviors on ARM and x86 architecture CPUs...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development? How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development? Apr 19, 2025 pm 07:15 PM

Discussing the hierarchical architecture problem in back-end development. In back-end development, common hierarchical architectures include controller, service and dao...

In Java remote debugging, how to correctly obtain constant values ​​on remote servers? In Java remote debugging, how to correctly obtain constant values ​​on remote servers? Apr 19, 2025 pm 01:54 PM

Questions and Answers about constant acquisition in Java Remote Debugging When using Java for remote debugging, many developers may encounter some difficult phenomena. It...

How to convert names to numbers to implement sorting within groups? How to convert names to numbers to implement sorting within groups? Apr 19, 2025 pm 01:57 PM

How to convert names to numbers to implement sorting within groups? When sorting users in groups, it is often necessary to convert the user's name into numbers so that it can be different...

See all articles