You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Tim Singletary <ts...@vetinsite.com> on 2003/02/03 18:54:28 UTC
Scaling to large projects
I can't figure how to set up Ant so that it will scale to be usable
on a large project. Is there an 'Ant-way-of-doing-things' that I haven't
grokked yet?
For example, suppose my source files are
com/x/app/Application.java
com/x/util/Alpha.java
com/x/util/Beta.java
And packages are as you'd expect.
Initially, I could try a com/x/app/build.xml like:
<project name="com.x.app.Application" default="compile" basedir="../..">
<target name="compile">
<javac srcdir="." destdir=".">
<include name="com/x/app/*.java"/>
<include name="com/x/util/*.java"/>
</javac>
</target>
</project>
(Question: is this a reasonable build.xml? Should it be in com/x/app,
or would you keep it somewhere else? Would you use a different
project name, a different basedir, would you do the javac element
differently, etc.?)
One scaling problem is that I might not want to compile everything in
com/x/util - perhaps the still-being-developed DoesntWorkYet.java
doesn't compile. I could change the javac element to:
<javac srcdir="." destdir=".">
<include name="com/x/app/Application.java">
<include name="com/x/util/Alpha.java">
<include name="com/x/util/Beta.java">
</java>
but it's obvious that this direction of changes won't scale - suppose
com/x/util gets refactored to require com/x/util/NewStuff.java, etc.;
I don't want com/x/app to have to know the details of how com/x/util
is structured.
I could try using XML entities - after all, com/x/util is the best
place to keep the list of files I need to include - I might create
com/x/util/includes.xml:
<include name="com/x/util/Alpha.java">
<include name="com/x/util/Beta.java">
and change com/x/app/build.xml to:
<?xml version="1.0"?>
<!DOCTYPE project [
<!ENTITY com.x.util.includes SYSTEM "file:../util/includes.xml">
]>
<project name="com.x.app.Application" default="compile" basedir="../..">
<target name="compile">
<javac srcdir="." destdir=".">
<include name="com/x/app/Application.java"/>
&com.x.util.includes;
</javac>
</target>
</project>
But com/x/util/includes.xml might itself use entities that
com/x/app/build.xml hasn't defined. (XML's parameter entities might
provide a solution)
Or, stuff in com/x/util might be machine generated and thus might
impose dependancies on com/x/app's build.xml's compile target.
What's the Ant way of solving these kinds of problems?
tim
Re: Scaling to large projects
Posted by "M. Erik Husby" <mh...@genome.wi.mit.edu>.
The simplest way to scale to a large project is to organize your directories in a fashion
similar to this:
project
build.xml
- src
(all package sources)
- classes
(where all class files will end up.)
- lib
(where all third party jar files live)
- deploy
( where you put the deployable files )
Then your build.xml can contain things like:
<path id="base.path">
<pathelement location="./classes"/>
<fileset dir="./lib">
<include name="**/*.jar"/>
</fileset>
</path>
<javac destdir="./classes">
srcdir="./src">
<classpath refid="base.path"/>
</javac>
Javac will compile everything under the source directory. You are free to add packages and refactor
classes as you see fit.
Erik Husby