2016-08-18 210 views
1

摘要无法获取ProGuard混淆和Sprint引导共同努力

我一直在试图让ProguardSpring-boot工作为obfuscation,但一直没能得到Spring-bootmaven建成后运行。我搜查了一下,发现一些人在谈论同一个问题,但我还没有看到它解决了。

我有2个应用程序。

  • A2需要A1
  • A1

我只真正需要的obfuscation建设成A2,但我非常希望将其建成两者。

我正在创建一个executableSpring-boot jar来运行A1和A3。

我能得到maven打包和创建executablejar但是当我运行它,我得到以下称compressed and nested jar files must be stored without compression堆栈跟踪。

问题

我怎样才能得到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

在Maven中,你是否将所有依赖关系放入一个单独的jar中执行?这可能是问题所在。我一直不得不将Spring库保存在可执行文件jar之外,以便它们正常工作。 – JRSofty

+0

@JRSofty是的,我试图让它构建一切,包括Spring和我所有的库。你如何设置你的构建,然后排除这些库并在运行时使用它们?你是在没有弹簧库的情况下构建混淆瓶子,然后重建这个罐子和弹簧来制作一个可执行文件?谢谢 – ALM

+0

这可能是maven正在执行压缩。您可能需要检查文档。一个检查是编译没有proguard,看看jar是否运行或抛出相同的异常。 – JRSofty

回答

0

因此,正如我们在上面的评论中讨论的,这里是我如何处理这个。

第一步:你的依赖拷贝到外部文件夹使用maven-依赖性的插件是这样的:

<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。现在我不确定你正在使用哪个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中,那么应用程序运行得很好。