You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Mikael Petterson (KI/EAB)" <mi...@ericsson.com> on 2004/07/16 09:54:19 UTC

Depend task question

Hi,

When I read about the depend in the ant user's manual I get confused.

"The depend task works by determining which classes are out of date with respect to their source and then removing the class files of any other classes which depend on the out-of-date classes."

So this removes classes that depends on my out-of-date classes but it does not update them. Should I have some kind of if-statement "if classes are out-of-date then compile". How can I do this?

BR

//Mikael


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Depend task question

Posted by Peter Reilly <pe...@apache.org>.
The explaination is a little confusing, but it is a useful task.

Suppose one has to classes A and B:

A.java:
public class A {
   B b = new B();
}
B.java:
public class B {
}

One can compile these as follows:

<javac srcdir="src" destdir="classes"/>

Suppose one changes B.java as follows:
B.java:
public class B {
  public B(int value) {
  }
}

One compiles again:
<javac srcdir="src" destdir="classes"/>

This only recompiles B.java ! and does not make a new A.class.
So later, when one tries to use A.class, one gets
java.lang.NoSuchMethodError: B: method <init>()V not found

To fix this one can place:
<depend srcdir="src" destdir="classes" depcache="depcache"/>
before the <javac/> call.

What depend does  is that it sees that B.class is older that B.java, so it
knows that B.class needs to be made again, it then looks for the other
classes and sees that A.class uses B.class so it knows that A.class needs to
be made again. As a result of this, it deletes B.class and A.class so when
the <javac> call is made, both A.java and B.java will be compiled.

Peter.

Mikael Petterson (KI/EAB) wrote:

>Hi,
>
>When I read about the depend in the ant user's manual I get confused.
>
>"The depend task works by determining which classes are out of date with respect to their source and then removing the class files of any other classes which depend on the out-of-date classes."
>
>So this removes classes that depends on my out-of-date classes but it does not update them. Should I have some kind of if-statement "if classes are out-of-date then compile". How can I do this?
>
>BR
>
>//Mikael
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org