我试图保护我的jar项目。我只需要收缩可用,所以这是我的配置:
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>4.3</proguardVersion>
<options>
<option>-dontobfuscate</option>
<option>-optimizationpasses 5</option>
<option>-dontoptimize</option>
<option>-ignorewarnings</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-dontpreverify</option>
<option>-verbose</option>
<option>-dontwarn</option>
<option>-dontnote</option>
<option>-keepattributes SourceFile, SourceDir</option>
<option>-keepattributes *Annotation*</option>
<option><![CDATA[
-keep class com.myclass.document.** { *; }
-keep class com.myclass.connectivity.** { *; }
-keep class com.myclass.util.** { *; }
-keep class ch.boye.httpclientandroidlib.** { *; }
-keep class com.google.** { *;}
-keep class org.joda.time.** { *;}
-keep class org.apache.log4j.** { *;}
-keep class org.apache.commons.** { *;}
-keep class java.util.Iterator { *;}
-keepclasseswithmembernames class * { native <methods>; }
-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
]]>
</option>
</options>
<maxMemory>256m</maxMemory>
<injar>${project.build.finalName}-jar-with-dependencies.jar</injar>
<outjar>${project.build.finalName}-jar-with-dependencies.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<addMavenDescriptor>false</addMavenDescriptor>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard</artifactId>
<version>4.3</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
</plugin>
这个异常我开始,但我留下了几乎所有的文件(-keep),仍然得到这个异常:
FATAL UNEXPECTED EXCEPTION CAUGHT in thread main.main
java.lang.IncompatibleClassChangeError: Class com.google.common.collect.Iterators$7 does not implement the requested interface java.util.Iterator
at com.google.common.collect.Iterators.getNext(Iterators.java:860)
at com.google.common.collect.Iterators.find(Iterators.java:728)
at com.google.common.collect.Iterables.find(Iterables.java:656)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
可能与:是什么原因导致java.lang.IncompatibleClassChangeError有关?
添加:
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>