ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roman Kennke <>
Subject Re: Advanced includes/excludes for javac
Date Mon, 23 Jun 2008 19:25:23 GMT
Hi Dominique,

> > I have a problem with the javac task that I cannot solve, maybe somebody
> > can help me. Let's say I have a directory layout like this:
> >
> > src/proj1/
> > src/proj1/
> > src/proj2/
> > src/proj2/
> >
> > Now I want to compile Class1 from proj1 and Class2 from proj2 and
> > exclude the other two. Also, I need to compile those in one go because
> > they depend on each other. I didn't find a way to implement this using
> > the srcdir attribute, or nested src tags. Any ideas?
> The only way to do this is by resetting srcdir to an empty string.
> That's the technique <compilewithwalls> and others (including me) have
> used in the past.
> That way, Javac will compile *only* the file explicitly given to it,
> and never implicitly compile files the explicitly given classes depend
> on (which will lead to compile failures if the depend classes aren't
> found via the classpath).
> AFAIK, <javac> will accept several nested <fileset>s, so that's how
> you include source files from several directories (but remember to
> scrdir=""). --DD

Yeah, I suppose this would work. But it would have the disadvantage that
the javac task could not map the sources to the .class files, and would
recompile everything on each invocation. Correct me if I'm wrong.

However, I think I found a better solution that works for me. Instead of
compiling it in one go, I compile it in 2 steps, and in the 1st step I
set the -sourcepath to the other sources dir, so that javac pulls in the
required sources from the other project. Then in the second step, I set
the classpath to the directory into which the 1st step built its
classes, so that it picks up the correct dependencies again. In both
steps I can set the necessary includes/excludes. For the simplified
example I gave above, this would look like:

    <javac srcdir="proj1" excludes="" destdir="classes"

    <javac srcdir="proj2" excludes="" destdir="classes"
           classpath="classes" />

Of course, having this in one javac task invocation would be much nicer.

Cheers, Roman


View raw message