The following example demonstrates how you can make use of the Jalopy Ant task.
Note that the "format" target depends on the "compile" target. This way we can be sure that the given classpathref does cover all types used in the sources.
Example 4.1. Example Ant build file
<?xml version="1.0" ?> <project name="myProject" default="format" basedir="." > <property name="dir.compile" value="${basedir}/tmp~/build/classes" /> <property name="dir.lib" value="${basedir}/lib" /> <property name="dir.src.java" value="${basedir}/src/java" /> <!-- ==================================================================== --> <!-- Defines the project classpath --> <!-- ==================================================================== --> <path id="project.classpath" > <!-- our compilation directory --> <pathelement location="${dir.compile}" /> <!-- needed 3rd party libraries --> <fileset dir="${dir.lib}" > <include name="**/*.jar" /> </fileset> </path> <!-- ==================================================================== --> <!-- Defines the Jalopy task --> <!-- ==================================================================== --> <taskdef name="jalopy" classname="com.triemax.JalopyTask" /> <!-- ==================================================================== --> <!-- Compiles the project sources --> <!-- ==================================================================== --> <target name="compile"> <javac destdir="${dir.compile}" fork="true"> <classpath refid="project.classpath" /> <src path="${dir.src.java}" /> </javac> </target> <!-- ==================================================================== --> <!-- Formats the project source --> <!-- ==================================================================== --> <target name="format" depends="compile"> <!-- Invokes Jalopy as follows: - load the code convention from the given url - the import optimization feature will work (if enabled in the code convention), because a classpath reference is given - all formatted files will have unix file format (\n) - the processing will be performed in a separate VM - override the convention to use alder32 checksums of files as history policy - override the convention to use loglevel 'info' - the user environment variable 'author' is set and the value 'John Doo' assigned Since Jalopy 1.3 an include pattern is no longer necessary if you want to format all supported source files of a directory structure --> <jalopy convention="http://www.foo.com/cisco-omg.xml" classpathref="project.classpath" fileformat="unix" fork="true" history="adler32" loglevel="info"> <variable name="author" value="John Doo" /> <fileset dir="${dir.src.java}"> <include name="**/*.java" /> <include name="**/*.sqlj" /> </fileset> </jalopy> </target> </project>