我正在使用Eclipse IDE和java 7中的maven架构项目开发Java应用程序
我需要生成一个混淆的jar文件,该文件也必须包含所有在其中混淆的依赖项我一直在检查一些解决方案但我无法获得所需的结果。
我检查过的一些地方是:
来自我的大部分当前实现的两个第一个链接
这是我的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>
我得到的错误如下:
[错误]无法执行目标 com.pyx4me:proguard-maven-plugin:2.0.4:项目的proguard(默认) CacheClienteModelC:无法重命名 E:\用户\ B267481 \文档\ ServidorDesarroCreditoAcertum \ CacheClienteModelC \目标\ CacheClienteModelC.jar - &GT; [帮助1]
只是为了让事情更清楚 当我构建项目时,在目标文件夹(CacheClienteModelC-jar-with-dependecies.jar和CacheClienteModelC.jar)中生成两个不同的jar,我尝试生成的文件是CacheClienteModelC-small.jar(混淆jar),这是永远不会创造。
我应该如何配置插件来混淆项目的文件?
答案 0 :(得分:2)
您正在为Maven使用旧版本的proguard插件,您应该使用this一个,您可以在Maven Central存储库中找到它。
现在,对于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。尝试一下。