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>
本文提供了一个完整的 Ant build.xml 文件示例,用于 Eclipse 中 J2SE 应用程序的编译、打包及代码压缩、优化与混淆。通过这个文件,你可以一次性完成从源代码到最终发布版的所有步骤。
1145

被折叠的 条评论
为什么被折叠?



