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

自闭症网瘾萝莉.ら 提交于 2019-12-10 17:24:26

问题


I have one project which is part of another one. I am using maven build process to make project's jar. I used ProGuard to obfuscate it. I have some controllers which handles UI requests.

Q. My problem is un-obfuscated jar is working. All controllers are getting hit, but obfuscated jar is not working (none controller gets hit). Whats the issue with obfuscation ?

My Servlet.XML :

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

Sample controller code :

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
    }
}

My POM.XML contents related to 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>

My ProGuard.conf file contents :

-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'

I checked my obfuscated jar, all annotations are persisted. Also in my information package I have some other classes which have package level access only. So those are getting obfuscated too. But all my classes which have RequestMappings are public and not getting obfuscated.

My running environment :

1) Java 1.7 for my project. But this jar is getting placed in project which is running on Java 1.8

2) ProGuard version : 5.2.1

3) Spring : 4.0.9

4) Jackson : 1.9.11

(Note : Un-ofuscated jar is working but obfuscated is not working in above environment)


回答1:


I need to add following in ProGuard.conf file

-keepdirectories

Directory entries are removed by default in obfuscation process. This is done to reduce size of jar. As I use "component-scan" feature of Spring (which may need directory structure) I need to keep it to work properly.



来源:https://stackoverflow.com/questions/40669903/proguard-obfuscated-jar-is-not-working-but-un-obfuscated-jar-is-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!