I'm sending this for a co-worker whose mail is temporarily broken. He
does subscribe to the ant-dev list so should see any responses. Thanks
for any help you can give us.
--Steve
"We have a government of law, and government officials must
be held accountable under the law."
-- Judge Royce Lamberth
U.S. District Court for the District of Columbia
---------- Forwarded message ----------
Date: Mon, 14 Aug 2000 15:44:22 -0400
From: Matthew Kuperus Heun <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Greetings:
I'm new to ant, and I'm trying to understand the way ant compiles
with the javac task. I'm running into the classic dependency
problem, and I'm wondering if ant provides an elegant solution.
If I have the files ClassA.java, ClassB.java, and build.xml (shown
below) everything works great.
However, if I change the API on ClassA from
public void testMethod(int input)
to
public void testMethod(String input){
ant does not know to recompile classes that depend on ClassB. In
this simple case, only ClassA is recompiled, although both ClassA and
ClassB should be recompiled because ClassB makes a call to ClassA.
However, only ClassA is recompiled, and I get a runtime runtime error
which should have been caught at compile time.
I know I could execute the clean target first, but that is
inefficient and overkill for a project that has hundreds or thousands
of class files. Is there a way to have ant automatically recompile
dependents like ClassB?
Cheers,
Matt
-----------------------------
****** ClassA.java **************************************
public class ClassA extends Object {
public void testMethod(int input){
System.out.println("input = " + input);
}
}
****** ClassB.java **************************************
public class ClassB extends Object {
int value = 10;
public static void main(String argv[]){
ClassB b = new ClassB();
try {
b.testMethod();
} catch (Exception e){
System.out.println("############### Failure! ##################");
}
System.out.println("!!!!!!!!!!!!!!!! Success! !!!!!!!!!!!!!!!!");
}
public void testMethod(){
ClassA a = new ClassA();
a.testMethod(value);
}
}
***** The build file ***************************************
<?xml version="1.0"?>
<!--
=======================================================================
-->
<!-- Build file to test ant dependencies
-->
<!--
=======================================================================
-->
<project name="TestAnt" default="run" basedir=".">
<property name="Name" value="TestAnt"/>
<property name="ant.home" value="."/>
<property name="src.dir" value="${ant.home}"/>
<property name="build.classes" value="build/classes"/>
<!--
=====================================================================
-->
<!-- A compile target
-->
<!--
=====================================================================
-->
<target name="compile" >
<mkdir dir="${build.classes}"/>
<javac srcdir="${src.dir}"
destdir="${build.classes}">
<include name="**/*.java"/>
</javac>
</target>
<!--
=====================================================================
-->
<!-- A target to run the test
-->
<!--
=====================================================================
-->
<target name="run" depends="compile">
<java classname="ClassB">
<classpath>
<pathelement path="${build.classes}"/>
</classpath>
</java>
</target>
<!--
=====================================================================
-->
<!-- A target to zap the class files and start afresh
-->
<!--
=====================================================================
-->
<target name="clean">
<deltree dir="${build.classes}"/>
</target>
</project>
--
--
Matthew Kuperus Heun
Global Aerospace Corporation
+1 (978) 922-7115 (voice & fax)
<http://www.gaerospace.com>
<mailto:[EMAIL PROTECTED]>