摘要
我一直在努力让Proguard
与Spring-boot
obfuscation
合作,但在使用Spring-boot
进行构建后无法让maven
运行。我搜索过并发现有些人在谈论同样的问题,但我还没有看到它解决了。
我有2个申请。
我只需要将obfuscation
构建到A2中,但理想情况下我想将它构建到两者中。
我正在创建一个executable
Spring-boot
jar来运行A1和A3。
我可以maven
打包并创建executable
jar
,但是当我运行它时,我会在下面找到compressed and nested jar files must be stored without compression
的堆栈跟踪。
问题
如何在不压缩嵌套jar的情况下让proguard
构建我的应用程序?
谢谢
堆栈跟踪
Exception in thread "main" java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/commons-lang3-3.4.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
at org.springframework.boot.loader.c.k.e(JarFile.java:285)
at org.springframework.boot.loader.c.k.c(JarFile.java:260)
at org.springframework.boot.loader.c.k.a(JarFile.java:248)
at org.springframework.boot.loader.c.k.a(JarFile.java:237)
at org.springframework.boot.loader.a.c.a(JarFileArchive.java:103)
at org.springframework.boot.loader.a.c.a(JarFileArchive.java:87)
at org.springframework.boot.loader.a.c(ExecutableArchiveLauncher.java:72)
at org.springframework.boot.loader.c.a(Launcher.java:49)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
POM的插件详细信息
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.13</version>
<executions>
<execution>
<id>proguard</id>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- File with proguard configuration -->
<proguardInclude>${basedir}/proguard.conf</proguardInclude>
<obfuscate>true</obfuscate>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
<options>
<option>-optimizations !class/marking/final</option>
<option>-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF,META-INF/spring.*</option>
<option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
<option>-keepclasseswithmembers public class * { public static void main(java.lang.String[]);}</option>
</options>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.2.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Proguard.conf
# Don't obfuscate or remove your entry point
-keep public class com.something.InitialRunner{public static void main(java.lang.String[]);}
-ignorewarnings
-dontoptimize
-dontshrink
# Uncomment if you want to have more meaningful backtraces
# Useful for obfuscation debugging
# You absolutely must keep this commented out for production
#-keepattributes SourceFile,LineNumberTable
答案 0 :(得分:0)
正如我们在上面的评论中所讨论的,这是我如何处理这个问题。
第一步:将依赖项复制到外部文件夹使用maven-dependency-plugin,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
第二步:使用Maven执行你的程序。现在我不确定你使用的是哪个proguard插件,我使用的是wvengen中的插件。
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.12</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
<configuration>
<obfuscate>true</obfuscate>
<outputDirectory>target</outputDirectory>
<proguardInclude>proguard.conf</proguardInclude>
<libs>
<lib>C:\Program Files\Java\jre1.8.0_65/lib/rt.jar</lib>
<lib>C:\Program Files\Java\jre1.8.0_65/lib/jsse.jar</lib>
</libs>
</configuration>
</execution>
</executions>
</plugin>
第三步:检查您的依赖项是否列在proguard.conf文件中
# Use -libraryjars to list every jar found in the target/libs folder.
# Don't obfuscate or remove your entry point
-keep public class com.something.InitialRunner{public static void main(java.lang.String[]);}
-ignorewarnings
-dontoptimize
-dontshrink
# Uncomment if you want to have more meaningful backtraces
# Useful for obfuscation debugging
# You absolutely must keep this commented out for production
#-keepattributes SourceFile,LineNumberTable
鉴于可能有一种方法可以使用Maven自动执行此操作,因此您无需手动添加它们,但这是我如何处理它。一旦我在混淆之前让Spring不被包裹在主jar中,那么应用程序运行就好了。