ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conor MacNeill" <co...@cortexebusiness.com.au>
Subject RE: Dependencies
Date Thu, 17 Aug 2000 01:09:27 GMT
Stefan,

> From: Stefan Lecho [mailto:Stefan.Lecho@iconmedialab.com]
> Hello,
>
> I have the following tree structure:
>
> project
>    ----classes = ${dest.basedir}
> 		----com
> 			----something
> 				----somethingelse
>    ----sources
> 		----com
> 			----something
> 				----somethingelse = ${somethingelse.src.dir}
>
> and the following task:
>   <target name="compile.somethingelse" depends="">
>     <javac srcdir="${somethingelse.src.dir}"
>            destdir="${dest.basedir}"
> 	   classpath="${classpath}">
>     </javac>
>   </target>
>
> Now my problem:
>
> If I run "ant compile.somethingelse" twice, the source files in the
> somethingelse directory are compiled, although nothing changed. I realise
> that the dependencies of the target are incorrect, but I don't find a
> solution. Adding the "includes name=${dest.basedir}/**" tag
> doesn't seem to
> work.
>

Stefan,

When the javac task determines whether to compile a java file into a class
file, it uses the location of the java source file relative to the srcdir
parameter to determine the package. It then will check if a class file
exists in the corresponding location in the destination directory. Since you
have set your srcdir to the location of the .java files, the javac task
assumes that these classes belong to the root package and it expects their
class files to the found in ${dest.basedir}. The javac task DOES NOT read
your source file to determine the package location of the class.

Once the javac task has decided to recompile the file it gives it to the
javac compiler. The compiler DOES read the package statement and puts the
compiled class in its appropriate location in the destination hierarchy but
this is NOT where the javac task will expect them to be the next time you
compile.

The solution is to set a property to the root of your source tree and then
filter out the source files you want to compiler. Your include directive was
looking at the destination tree and not the source tree.

Try this

   <property name="src.dir" value="source"/>

   <target name="compile.somethingelse" depends="">
     <javac srcdir="${src.dir}"
            destdir="${dest.basedir}"
 	   classpath="${classpath}">
	 <include name="com/something/somethingelse/**"/>
     </javac>
   </target>

There are other benefits to this arrangement, namely that javac, the
compiler, will be able to do its automatic compiling of files for which
class files do not exist.

Conor


Mime
View raw message