账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    我用proguard混淆一个Spring mvc+mybatis项目后,war文件里没有应有的class文件是怎么回事?
    75
    0

    这是一个IDEA的maven项目。

    我把项目名target项目名-1.0-small.war文件解压缩后,WEB-INFclasses包名下除了xml文件,都是空的。

    build信息:
    [proguard] Note: there were 84 unkept descriptor classes in kept class members.
    [proguard] You should consider explicitly keeping the mentioned classes
    [proguard] (using '-keep').
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Note: there were 9 unresolved dynamic references to classes or interfaces.
    [proguard] You should check if you need to specify additional program jars.
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Note: there were 5 class casts of dynamically created class instances.
    [proguard] You might consider explicitly keeping the mentioned classes and/or
    [proguard] their implementations (using '-keep').
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Note: there were 65 accesses to class members by means of introspection.
    [proguard] You should consider explicitly keeping the mentioned class members
    [proguard] (using '-keep' or '-keepclassmembers').
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Note: you're ignoring all warnings!
    [proguard] Ignoring unused library classes...
    [proguard] Original number of library classes: 19879
    [proguard] Final number of library classes: 19879
    [proguard] Setting target versions...
    [proguard] Printing kept classes, fields, and methods...
    [proguard] Warning: there were 10914 unresolved references to classes or interfaces.
    [proguard] You may need to add missing library jars or update their versions.
    [proguard] If your code works fine without the missing classes, you can suppress
    [proguard] the warnings with '-dontwarn' options.
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Warning: there were 203 unresolved references to program class members.
    [proguard] Your input classes appear to be inconsistent.
    [proguard] You may need to recompile the code.
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Warning: there were 26 unresolved references to library class members.
    [proguard] You probably need to update the library versions.
    [proguard] (http://proguard.sourceforge.n...
    [proguard] Inlining subroutines...
    [proguard] Obfuscating...
    [proguard] Printing mapping to [C:UserswinIdeaProjects项目名targetproguard_map.txt]...
    [proguard] Preverifying...
    [proguard] Writing output...
    [proguard] Preparing output war [C:UserswinIdeaProjects项目名target项目名-1.0-small.war]
    [proguard] Copying resources from program war [C:UserswinIdeaProjects项目名target项目名-1.0.war] (filtered)
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install (default-install) @ 项目名 ---
    [INFO] Installing C:UserswinIdeaProjects项目名target项目名-1.0.war to C:Userswin.m2repositorycomsmart项目名1.0项目名-1.0.war
    [INFO] Installing C:UserswinIdeaProjects项目名pom.xml to C:Userswin.m2repositorycomsmart项目名1.0项目名-1.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

    proguard.conf文件的内容:

    忽略警告

    -ignorewarnings

    打印处理信息,失败时会打印堆栈信息

    -verbose

    保持目录结构

    -keepdirectories

    不能混淆泛型、抛出的异常、注解默认值、原始行号等

    -keepattributes Signature,Exceptions,Annotation,InnerClasses,Deprecated,EnclosingMethod

    对于包名、类名不进行混淆

    -keeppackagenames com.company.appname.**

    保留public、protected方法不被混淆

    -keep public class * {

      public protected *;

    }

    保留注解不被混淆

    -keep public @interface * {

    ** default (*);

    }

    保留枚举类不被混淆

    -keepclassmembers enum * {

    public static **[] values();
    public static ** valueOf(java.lang.String);

    }

    保持依赖注入不被混淆

    -keepclassmembers class * {

    @org.springframework.beans.factory.annotation.Autowired *;
    @javax.annotation.Resource *;

    }

    保持RMI调用不被混淆

    -keep class * implements java.rmi.Remote {

    <init>(java.rmi.activation.ActivationID, java.rmi.MarshalledObject);

    }

    保留JavaBean不被混淆

    -keepclassmembers class * implements java.io.Serializable {

    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();

    }

    避免类名被标记为final

    -optimizations !class/marking/final

    -target 1.8 ##指定java版本号
    -dontshrink ##默认是开启的,这里关闭shrink,即不删除没有使用的类/成员
    -dontoptimize ##默认是开启的,这里关闭字节码级别的优化
    -useuniqueclassmembernames ##对于类成员的命名的混淆采取唯一策略
    -adaptclassstrings ## 混淆类名之后,对使用Class.forName('className')之类的地方进行相应替代
    -dontusemixedcaseclassnames ## 混淆时不生成大小写混合的类名,默认是可以大小写混合

    pom.xml文件:

        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.14</version>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>5.3.3</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <proguardVersion>5.3.3</proguardVersion>
                <obfuscate>true</obfuscate>
                <injar>项目名-1.0.war</injar>
                <outjar>项目名-1.0-small.war</outjar>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <proguardInclude>${project.basedir}/proguard.conf</proguardInclude>
                <libs>
                    <!-- Include main JAVA library required.-->
                    <lib>${java.home}/lib/rt.jar</lib>
                    <!-- Include crypto JAVA library if necessary.-->
                    <lib>${java.home}/lib/jce.jar</lib>
                </libs>
            </configuration>
        </plugin>
    
    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版

    回答动态

    师傅被妖怪抓走了:发布了悬赏问题火爆全网的“元宇宙”到底是什么?预计能赚取 1积分收益
    酒后略带风情:发布了悬赏问题Android内存中Graphics与Code占用过高预计能赚取 10积分收益
    扛起拖把扫天下:发布了悬赏问题typescript如何导出接口配置?求解,谢谢!预计能赚取 10积分收益
    发布了悬赏问题Vue 如何改变返回页面的路径?如让B页面只能返回到A页面.预计能赚取 11积分收益
    发布了悬赏问题vue H5移动端;底部bottom固定定位,安卓弹起键盘导致页面变形如何解决?预计能赚取 10积分收益
    发布了悬赏问题请问为什么tomcat8.5 GET请求中文正常,POST请求还需要设置UTF-8.预计能赚取 10积分收益
    发布了悬赏问题vue2.5+ts创建以及引入jq的方法预计能赚取 11积分收益
    情场浪女:发布了悬赏问题import ggplot时报错module 'pandas' has no attribute 'tslib'预计能赚取 10积分收益
    见心书画许老师18753375161:发布了悬赏问题echarts3 legend禁止点击事件,允许悬浮事件预计能赚取 11积分收益
    aa_92cb0bd09f:发布了悬赏问题codewar上的一个问题预计能赚取 11积分收益