A)Project configs
<!-- Project configs -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.gt</groupId>
<artifactId>maven-proguard-test</artifactId>
<packaging>jar</packaging>
<version>-ver.01</version>
<name>maven-proguard-test-application</name>
<properties>
<project.build.mainClass>com.gt.App</project.build.mainClass>
</properties>
B) Proguard Configuration in pom.xml :
<!-- Proguard configs -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
<!-- run proguard at package phase -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<archive>
<manifest>
<mainClass>${project.build.mainClass}</mainClass>
</manifest>
</archive>
<options>
<option>-allowaccessmodification</option>
<option>-dontshrink</option>
<option>-keepattributes *Annotation*</option>
<option>-keep public class ${project.build.mainClass} { *; }</option>
<!-- <option>-keep public class [com.qualified_name]</option> -->
<!-- if you want to keep enum classes, this is generally expected -->
<option>-keep public enum * { *;}</option>
</options>
<outjar>${project.build.finalName}.jar</outjar>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard</artifactId>
<version>4.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
C)Maven jar plugin to make .jar file
<!-- making jar file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${project.build.mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
D)Maven dependency plugin - copy jar dependencies
<!-- maven dependency plugin to copy all dependency jar to a folder, here
copying to target/lib -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
E)run.bat file to run the jar file ( it loads the jar files in classpath) You need to copy run.jar file to target folder. com.gt.App is my main class.
@echo off
Start "" /B javaw -Xmx256M -cp "maven-proguard-test-0.0.1-SNAPSHOT.jar;lib/*" com.gt.App
F)Build command : mvn clean compile package
Project folder structure :
The complete Source CODE at Google Code SVN Repo :
http://code.google.com/p/maven-proguard-eclipse-java-project-configuration-working/
Hi ,
ReplyDeleteNice blog! Is there an email address I can contact you in private?
of course... gtiwari333@gmail.com
DeleteNice blog...
ReplyDeleteThanks for this post. Can you please share how to obfuscate war(Spring3 + Maven) ?
ReplyDeleteNice post! Can you please share how to obfuscate war(Spring3 + Struts + Maven) ?
ReplyDelete