gpt4 book ai didi

maven - 如何为 Maven 项目生成混淆的 jar 文件

转载 作者:行者123 更新时间:2023-12-02 04:15:26 24 4
gpt4 key购买 nike

我正在 Eclipse IDE 和 java 7 中使用 maven 架构项目开发 java 应用程序

我需要生成一个混淆的 jar 文件,该文件还必须包含其中混淆的所有依赖项我一直在检查一些解决方案,但我一直无法获得所需的结果。

我检查过的一些地方是这样的:

Lin1 , Link2 , Link3

从前两个链接中,我基于当前的大部分实现

这是我的 pom.xml 文件:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>modeloconfigurador.cache</groupId>
<artifactId>CacheClienteModelC</artifactId>
<version>1.0</version>

<dependencies>
<dependency>
<groupId>modeloconfigurador.cache</groupId>
<artifactId>Serializer</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>

<!--<dependency> -->
<!--<groupId>com.pyx4me</groupId> -->
<!--<artifactId>proguard-maven-plugin</artifactId> -->
<!--<version>2.0.4</version> -->
<!-- </dependency> -->
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.10</version>
</dependency>


</dependencies>


<build>
<finalName>CacheClienteModelC</finalName>
<plugins>

<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>

<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>

<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>

<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>

</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- comienza configuracion proguard -->


<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>4.10</proguardVersion>
<options>

<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-small.jar</outjar>
<!-- <injar>CacheClienteModelC-jar-with-dependencies.jar</injar> -->
<!-- <outjar>CacheClienteModelC-small.jar</outjar> -->
<option>-allowaccessmodification</option>
<option>-keep public class main.Main { *; }</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
<dependencies>

<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.10</version>
<!--<version>5.2.1</version> -->
</dependency>

</dependencies>
</plugin>


<!-- termina configuracion proguard -->
</plugins>


</build>


</project>

我收到的错误如下:

[ERROR] Failed to execute goal com.pyx4me:proguard-maven-plugin:2.0.4:proguard (default) on project CacheClienteModelC: Can't rename E:\Users\B267481\Documents\ServidorDesarroCreditoAcertum\CacheClienteModelC\target\CacheClienteModelC.jar -> [Help 1]

编辑

只是为了让事情更清楚当我构建项目时,在目标文件夹中生成两个不同的jar(CacheClienteModelC-jar-with-dependecies.jar和CacheClienteModelC.jar),我尝试生成的文件是CacheClienteModelC-small.jar(混淆的jar),它是从未创建过。

我应该如何配置插件来混淆我的项目文件?

最佳答案

您正在使用旧版本的 Maven proguard 插件,您应该使用 this一,您可以在 Maven 中央存储库中找到它。

现在,对于您的 pom.xml,从依赖项中删除 com.pyx4me 依赖项,您在那里不需要它。

现在对于插件配置尝试如下:

<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.10</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-small.jar</outjar>
<includeDependency>true</includeDependency>
<options>
<option>-keep public class your.package.Main { *; }</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
<archive>
<manifest>
<mainClass>Main</mainClass>
<packageName>your.package</packageName>
</manifest>
</archive>

</configuration>
<dependencies>

<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.10</version>
<scope>runtime</scope>
</dependency>

</dependencies>
</plugin>

看看你是如何在其中指定 proguard 的依赖关系的?这应该会毫无问题地生成混淆的 jar。尝试一下。

关于maven - 如何为 Maven 项目生成混淆的 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326430/

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