gpt4 book ai didi

java - 混淆器 : Obfuscated jar is not working but un-obfuscated jar is working

转载 作者:搜寻专家 更新时间:2023-11-01 02:21:28 31 4
gpt4 key购买 nike

我有一个项目是另一个项目的一部分。我正在使用 ma​​ven 构建过程来制作项目的 jar。我使用 ProGuard 来混淆它。我有一些处理 UI 请求的 Controller 。

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

我的 Servlet.XML:

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

示例 Controller 代码:

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 内容:

<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 的类都是公开的,不会被混淆。

我的运行环境:

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

2) 混淆器版本:5.2.1

3) Spring :4.0.9

4) jackson :1.9.11

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

最佳答案

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

-keepdirectories

目录条目在混淆过程中默认被删除。这样做是为了减小 jar 的大小。当我使用 Spring 的“组件扫描”功能(可能需要目录结构)时,我需要让它正常工作。

关于java - 混淆器 : Obfuscated jar is not working but un-obfuscated jar is working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40669903/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com