ProGuard:混淆的 jar 不工作,但未混淆的 jar 工作

ProGuard : Obfuscated jar is not working but un-obfuscated jar is working

我有一个项目是另一个项目的一部分。我正在使用 maven 构建过程来制作项目的 jar。我使用 ProGuard 来混淆它。我有一些控制器可以处理 UI 请求。

问。我的问题是未混淆的 jar 正在工作。所有控制器都被击中,但混淆的 jar 不工作(none 个控制器被击中)。混淆有什么问题?

我的 Servlet.XML :

<context:component-scan base-package="myPackage.controllers" />
<mvc:annotation-driven />

示例控制器代码:

package myPackage.controllers.information;

import myPackage.beans.InfoBean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RestController
@RequestMapping("/information")
public class InformationController {

    @RequestMapping(method = RequestMethod.GET)
    public return_bean getAllInformation() {
        //some logic
    }

    @RequestMapping(value = "/{infoId}", method = RequestMethod.PUT)
    public return_bean updateInformation(@PathVariable String InfoId, @RequestBody InfoBean info) {
        // some logic
    }
}

我的 POM.XML 与 ProGuard 相关的内容:

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.13</version>
    <dependencies>
        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard-base</artifactId>
            <version>5.2.1</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <maxMemory>576m</maxMemory>
        <obfuscate>true</obfuscate>
        <!-- File with proguard configuration -->
        <proguardInclude>${basedir}/proguard.conf</proguardInclude>
        <libs>
            <lib>${java7home}/jre/lib/rt.jar</lib>
            <lib>${java7home}/jre/lib/jce.jar</lib>
        </libs>
    </configuration>
</plugin>

我的 ProGuard.conf 文件内容:

-dontnot
-dontwarn
-dontshrink
-dontoptimize
-keep public class * { public protected *;}
-keep class myPackage.controllers.** { public protected *;}
-keepattributes SourceFile,Signature,LineNumberTable,Exceptions, *Annotation*
-keepparameternames
-printmapping '${logFilesPath}/${project.artifactId}.log'

我检查了我的混淆jar,所有注释都被保留了。 在我的信息包中还有一些其他 类,它们只有包级访问权限。所以那些也变得模糊不清。但是我所有具有 RequestMappings 的 类 都是 public 并且没有被混淆。

我的运行环境:

1) Java 1.7 用于我的项目。但是这个 jar 被放置在 Java 1.8

上的 运行 项目中

2) ProGuard 版本:5.2.1

3) Spring : 4.0.9

4) 杰克逊:1.9.11

(注意 : 未混淆的 jar 正在运行,但混淆后的 jar 在上述环境中不起作用)

我需要在 ProGuard.conf 文件中添加以下内容

-keepdirectories

在混淆过程中默认删除目录条目。这样做是为了减小 jar 的大小。当我使用 Spring 的 "component-scan" 功能(可能需要目录结构)时,我需要保持它正常工作。