Proguard弹簧靴子罐项目无效后

时间:2018-09-28 06:30:03

标签: spring-boot proguard

我以前在ProGuard从事我的春季启动项目。执行ProGuard后,我的可执行项目无法工作。您可以在下面看到异常

  

例外是:

Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-boot-starter-data-rest-2.0.5.RELEASE.jar
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:86)
    at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/spring-boot-starter-data-rest-2.0.5.RELEASE.jar'
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:254)
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:239)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
    ... 4 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-boot-starter-data-rest-2.0.5.RELEASE.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.jar.JarFile.createJarFileFromFileEntry(JarFile.java:282)
    at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:262)
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:250)
    ... 6 more
  

我的pom.xml文件是:

        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.8</version>
            <configuration>
                <obfuscate>false</obfuscate>                   
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.logging.log4j</groupId>
                        <artifactId>log4j-api</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-parent</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-rest</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-jersey</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.mybatis</groupId>
                        <artifactId>mybatis</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.glassfish.hk2.external</groupId>
                        <artifactId>asm-all-repackaged</artifactId>
                    </exclusion>
                </exclusions>
                <options>
                    <option>-dontnote</option>
                    <option>-ignorewarnings</option>
                    <option>-dontwarn</option>
                    <option>-dontshrink</option>
                    <option>-dontoptimize</option>
                    <option>-dontpreverify</option>
                    <option>-keepparameternames</option>
                    <option>-keepdirectories **</option>
                    <option>-dontskipnonpubliclibraryclasses</option>                          
                    <option>-dontskipnonpubliclibraryclassmembers</option>    
                    <option>-keep class CitysurfsqlapiApplication</option>        
                    <option>-keepclasseswithmembers class com.citysurf.citysurfsqlapi.*</option>
                    <option>-keep class org.springframework.boot.loader.JarLauncher {public static void main(java.lang.String[]);}</option>
                    <option>-keep public class * { public protected *;}</option>
                    <option>-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF,META-INF/spring.*</option>
                    <option>-printmapping '${project.build.directory}/${project.artifactId}.log'</option>
                    <option>-keep class * extends *</option>
                    <option>-keep interface * extends *</option>
                    <option>-keep public class org.springframework.**</option>
                    <option>-keep public class * { public private *; }</option>
                    <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,LocalVariable*Table</option>
                    <option>-keepclassmembers class * {  @org.springframework.beans.factory.annotation.Autowired *; @org.springframework.beans.factory.annotation.Value *; @org.springframework.context.annotation.Bean *; @org.springframework.beans.factory.annotation.Qualifier *; @org.springframework.stereotype.Repository *; @org.springframework.data.repository.NoRepositoryBean *;}</option>
                    <option>-useuniqueclassmembernames</option>
                    <option>-keepattributes *Annotation*</option>
                    <option>-keep public class org.springframework.**</option>
                    <option>-keep class * { *; }</option>
                    <option>-keepdirectories</option>
                    <option>-allowaccessmodification</option>                        
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                    <lib>${java.home}/lib/jce.jar</lib>                        
                </libs>                    
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>5.2</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>

        </plugin>        

1 个答案:

答案 0 :(得分:0)

更改我的pom文件ProGuard之后,现在可以正常使用了。

        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.14</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.logging.log4j</groupId>
                        <artifactId>log4j-api</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.glassfish.hk2.external</groupId>
                        <artifactId>asm-all-repackaged</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-parent</artifactId>                            
                    </exclusion>
                </exclusions>

                <proguardVersion>5.3.3</proguardVersion>
                <injar>${project.build.finalName}.jar</injar>
                <outjar>${project.build.finalName}.jar</outjar>
                <obfuscate>true</obfuscate>
                <options>
                    <option>-dontshrink</option>
                    <option>-dontoptimize</option>
                    <!-- This option will replace all strings in reflections method invocations with new class names.
                    For example, invokes Class.forName('className')-->
                    <option>-adaptclassstrings</option>
                    <!-- This option will save all original annotations and etc. Otherwise all we be removed from files.-->
                    <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                        SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
                    <!-- This option will save all original names in interfaces (without obfuscate).-->
                    <option>-keepnames interface **</option>
                    <!-- This option will save all original methods parameters in files defined in -keep sections,
                    otherwise all parameter names will be obfuscate.-->
                    <option>-keepparameternames</option>
                    <!-- This option will save all original class files (without obfuscate) but obfuscate all in domain package.-->
                    <option>-keep class !com.slm.proguard.example.spring.boot.domain.** { *; }</option>
                    <!-- This option will save all original class files (without obfuscate) in service package-->
                    <!--<option>-keep class com.slm.proguard.example.spring.boot.service { *; }</option>-->
                    <!-- This option will save all original interfaces files (without obfuscate) in all packages.-->
                    <option>-keep interface * extends * { *; }</option>
                    <!-- This option will save all original defined annotations in all class in all packages.-->
                    <option>-keepclassmembers class * {
                        @org.springframework.beans.factory.annotation.Autowired *;
                        @org.springframework.beans.factory.annotation.Value *;
                        }
                    </option>
                </options>
                <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>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>5.3.3</version>
                </dependency>
            </dependencies>
        </plugin>

        <!-- Maven assembly must be run after proguard obfuscation so it take already obfuscated files.-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.citysurf.citysurfsqlapi.CitysurfsqlapiApplication</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>