ProGuard Eclipse Ant build.xml

If you are building J2SE apps with Eclipse and want to use ProGuard to compress, optimise or obfuscate your code you’ll need to create an Ant build.xml file to do this. I found various bits of help on the internet explaining parts of the build.xml file, but couldn’t find anywhere that gave the complete build.xml to do the full compile, jar and proguard steps.

Here is the full build.xml I cobbled together to do all three:

<?xml version="1.0" ?>

<project default="main">

<taskdef resource="proguard/ant/" 
	classpath="D:\apps\proguard4.0.1\lib\proguard.jar" />

<target name="main" depends="compile, jar, obfuscate" 
	description="Create project">
	<echo>Creating project.</echo>

<target name="compile" description="Compile target">
	<javac srcdir="src" destdir="bin"/>

<target name="jar" description="Jar target">
	<jar jarfile="PhotoStamper_debug.jar" 
		basedir="bin" includes="*.class">
		<attribute name="Main-Class" value="PhotoStamper" />

<target name="obfuscate" depends="jar" 
	description="Obfuscate compiled classes">
		  -libraryjars "${java.home}\lib\rt.jar"
		  -injars      PhotoStamper_debug.jar
		  -outjars     PhotoStamper.jar
		  -keep public class PhotoStamper {
			public static void main(java.lang.String[]);


Leave a Reply

Your email address will not be published. Required fields are marked *

Do NOT fill this !