ProGuard:混淆的jar无法正常运行,但未混淆的jar正常运行 [英] ProGuard : Obfuscated jar is not working but un-obfuscated jar is working

查看:251
本文介绍了ProGuard:混淆的jar无法正常运行,但未混淆的jar正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目属于另一个项目.我正在使用 maven 生成过程来制作项目的jar.我使用了 ProGuard 对其进行了模糊处理.我有一些控制器可以处理UI请求.

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.

问.我的问题是未混淆的罐子正在工作.所有控制器都被命中,但是混淆的jar无法正常工作(没有控制器被命中).混淆有什么问题?

我的Servlet.XML:

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

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

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>

我的ProGuard.conf文件内容:

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'

我检查了混淆的jar,所有注释都保留了. 另外,在我的信息包中,我还有其他一些仅具有包级别访问权限的类.因此,它们也变得令人困惑.但是我所有具有RequestMappings的类都是公共的,并且不会被混淆.

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.

我的运行环境:

1)我的项目使用Java 1.7.但是这个jar被放置在Java 1.8上运行的项目中

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

2)ProGuard版本:5.2.1

2) ProGuard version : 5.2.1

3)春季:4.0.9

3) Spring : 4.0.9

4)杰克逊:1.9.11

4) Jackson : 1.9.11

(注意:在上述环境中,未用药的广口瓶正在工作,但混淆后无法工作)

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

推荐答案

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

I need to add following in ProGuard.conf file

-keepdirectories

默认情况下,混淆过程中会删除目录条目.这样做是为了减小罐子的尺寸.当我使用Spring的组件扫描"功能(可能需要目录结构)时,我需要使其保持正常工作.

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.

这篇关于ProGuard:混淆的jar无法正常运行,但未混淆的jar正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆