I have recently started using Ant and came up with a few ideas while
migrating my build process to it. My directory structure is as follows:
Source tree:
/projects/src/servlet/client/Main.java
Classes tree:
/projects/classes/com/ibm/workflow/servlet/client/Main.class
That is, to avoid too much typing I put Main.java (and all the other files)
which is in the 'com.ibm.workflow.servlet.client' package in the
'servlet/client' subtree of my source tree.
Now when I compile my sources using the following task
<javac srcdir="/projects/src"
destdir="/project/classes"
includes="servlet/client/*.java"/>
It always recompiles all sources. This is because javac compares the
directories, but is missing the 'com/ibm/workflow' part of the directory.
A workaround is to first copy the sources to a fully named directory and
then compile from there:
<copydir src="/projects/src"
dest="/projects/ant/com/ibm/workflow"
includes="servlet/client/*.java"/>
<javac srcdir="/projects/ant"
destdir="/projects/classes"
includes="**/servlet/client/*.java"/>
But I don't like this approach so I thought one might simply add an
optional 'pkgdir' parameter to javac which would be used when comparing
srcdir and destdir. The task would then read like this:
<javac_pkg srcdir="/projects/src"
destdir="/projects/classes"
pkgdir="com/ibm/workflow"
includes="servlet/client/*.java"/>
I have already implemented this, it is just a few lines:
private String pkgDirName;
:
public void setPkgdir(String pkgDirName) {
this.pkgDirName = pkgDirName;
}
:
File pkgDir = pkgDirName == null ? destDir : new File(destDir,
pkgDirName);
scanDir(srcDir, pkgDir, files);
// compile the source files
:
What do you think?
-Erich