我用proguard混淆一个Spring mvc+mybatis项目后,war文件里没有应有的class文件是怎么回事?
这是一个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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论