views:

161

answers:

2

In Ant, what's the difference between <sourcepath> and <src> elements? I'm using them as sub elements of <javac>. I read through the manual but maybe I missed the definition of <src>.

Thanks!

+1  A: 

sourcepath is a path to the source files. It is useful for sending a previously defined path reference, but what it is primarily doing is directly representing the path as the parameter to javac.

srcdir is the default value to sourcepath, and kind of the simple way to point to one directory as the one containing the source files (the typical use case).

src elements are a way of specifying multiple source locations with different exclusions in each. It is used when you have a complicated source tree with parts in different locations that you want to compile. Basically when you directory structure doesn't match well with the compilation unit.

Yishai
Thanks for the synopsis. Can you think of a reason why it wouldn't work to put my various source locations all under a single <src> (as <pathelement>'s), but it would work to put two particular locations under <src> and the rest under <sourcepath>? It's strange indeed.
John B.
@John B., I would have to see the script and understand the locations to even guess.
Yishai
A: 

<javac> tasks <sourcepath> child corresponds to -sourcepath flag of javac command. This flag specifies directories, JAR files or ZIP files containing source files to compile.

The javac command can also be used by specifying a list of files on the command line. To pass such a list to javac command, you should use the <src> child element (or srcdir attribute) of <javac> task.

If your source files are in directories on the filesystem, the two do not make any difference in practice.

binil