Technology, life, programming, travel and money.

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/task.properties"
	classpath="D:\apps\proguard4.0.1\lib\proguard.jar" />
<target name="main" depends="compile, jar, obfuscate"
	description="Create project">
	<echo>Creating project.</echo>
</target>
<target name="compile" description="Compile target">
	<javac srcdir="src" destdir="bin"/>
</target>
<target name="jar" description="Jar target">
	<jar jarfile="PhotoStamper_debug.jar"
		basedir="bin" includes="*.class">
		<manifest>
		<attribute name="Main-Class" value="PhotoStamper" />
		</manifest>
	</jar>
</target>
<target name="obfuscate" depends="jar"
	description="Obfuscate compiled classes">
	<proguard>
		  -libraryjars "${java.home}\lib\rt.jar"
		  -injars      PhotoStamper_debug.jar
		  -outjars     PhotoStamper.jar
		  -keep public class PhotoStamper {
			public static void main(java.lang.String[]);
			  }
	</proguard>
</target>
</project>



Leave a Reply

Do NOT fill this !