It's worth considering adding to the "compile" target so that it includes a "<depend>" task right before the "<javac>" task. "<javac>" alone does an OK but imperfect job of dependency checking and recompiling; preceding it with the appropriate <depend> makes the dependency checking almost perfect (though nothing can detect things like dependencies introduced because of run-time reflection...)
For example, say class A imports and uses class B. Then say everything is compiled and brought up to date. Next, say B is changed. Without a preceding <depend> invocation, <javac> will see that B.java is newer than B.class, so it'll recompile B. However, <javac> will not determine that A should also be recompiled, even though A might call a method in B whose signature has changed. When <depend> is used though, it will remove A.class when it sees that B has been modified, since <depend> (unlike <javac>) "knows" that A uses B.
Anyway, here's the documentation for <depend> :
http://ant.apache.org/manual/OptionalTasks/depend.html
Unfortunately, I don't have the time to add the exact <depend> element to the sample buildfile, but roughly speaking, the structure of the <depend> task mirrors that of the <javac> that follows it (especially in terms of the source and destination directories/files). In addition though, I like to add "closure=true" and "cache=${cacheDir}" attributes to the <depend> task.
Anyway, I also encourage people to take the time to learn about Ant features. I recently switched from using "make" to Ant, and I think Ant is far better...
Hope this helps, Rich Wagner
From: Conor MacNeill <[EMAIL PROTECTED]> Reply-To: "Ant Users List" <[EMAIL PROTECTED]> To: "Ant Users List" <[EMAIL PROTECTED]> Subject: Re: just not getting it Date: Mon, 11 Aug 2003 11:25:34 +1000
Here is a complete and relatively simple example of a full build file to compile and build a jar. This particular example uses a set of external libraries in the build. If you don;t need that, you can drop out the lib.classpath related stuff.
<project name="piston" default="jar"> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="lib.dir" value="lib"/> <property name="jar.dir" value="jar"/>
<path id="lib.classpath"> <fileset dir="${lib.dir}"/> </path>
<target name="compile"> <mkdir dir="${build.dir}"/> <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"> <classpath refid="lib.classpath"/> </javac> </target>
<target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/piston.jar"> <fileset dir="${build.dir}"/> <manifest> <attribute name="Main-Class" value="com.codefeed.piston.Piston"/> </manifest> </jar> </target> </project>
On Mon, 11 Aug 2003 06:44 am, Gregory Seidman wrote:
>
> Would someone please explain how to handle the simple example of a
> directory/package tree full of .java source files to be built into a JAR?
> Once I have that toehold, I think I can start learning the rest.
>
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]