You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Martin Cooper <ma...@tumbleweed.com> on 2000/10/10 06:11:13 UTC

Questions about the task

I have a couple of questions about the way the <war> task is intended to be
used, since I seem to be having problems getting it to behave the way I
want.

1) For any error relating to a missing directory that I refer to, Ant gives
me an IllegalStateException with "basedir does not exist". This error is
incorrect, and when I finally figure out which directory is really missing,
it goes away without any change to the basedir value. This seems like a bug
to me...

2) Where should basedir normally point to? Is it expected to point at the
source root or the build root or somewhere else? If I point it at my build
root, I end up with my class files being included directly in the war file,
in addition to being included in their correct location (under WEB-INF) by
the <classes> element. It doesn't seem right that I should have to
explicitly exclude them in the <war> task itself, so I suspect I'm doing
something wrong.

3) Is there a way to specify a <fileset> that refers to a directory that may
or may not exist, without incurring an error if it does not? For example, if
I have <fileset dir="${mydir}/images"/> in my <war> task, I want it to
succeed if there is no 'images' subdirectory (yet) under the $mydir
directory. This would allow me to create a more generic build file, without
having to come back and modify it later when extra directories are added.

Thanks!

--
Martin Cooper
Tumbleweed Communications




Re: Questions about the task

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "MC" == Martin Cooper <ma...@tumbleweed.com> writes:

 MC> 1) For any error relating to a missing directory that I refer to,
 MC> Ant gives me an IllegalStateException with "basedir does not
 MC> exist".

Hmm, maybe you are using an older version of <war> than I am. I cannot
find any place where the task (or a superclass of it or FileSet) would
throw an IllegalStateException.

 MC> 2) Where should basedir normally point to?

Let me just point out how <war> is intended to be used - and please
help us clarify the documentation if it isn't:

When building web applications in our team at BoST there are several
"specialists" working in different directories - even using different
repositories for some things. 

I've found myself copying the static contents from our graphics
department and the HTML guys over to the place where the JSPs have
been built, creating a WEB-INF directory there and adding the
deployment descriptor as well as JAR files far too often.

<war> is just a simple <jar> task that tries to assemble scattered
pieces without the need to copy them into the "correct" directory
structure. So instead of

<mkdir dir="scratch/WEB-INF/lib" />
<copydir src="static-html-files" dest="scratch" />
<copydir src="graphics-from-somewhere-else" dest="scratch" />
<copydir src="some-jsps" dest="scratch" />
<copyfile src="deployment.descriptor" dest="scratch/WEB-INF/web.xml" />
<copyfile src="jdbc-driver.jar" dest="scratch/WEB-INF/lib/jdbc-driver.jar" />
<copyfile src="my-servlets.jar" dest="scratch/WEB-INF/lib/my-servlets.jar" />
<jar jarfile="myapp.war" basedir="scratch" />
<deltree dir="scratch" />

I've built a single task that builds the same file structure but
doesn't need a scratch dir or copying of files at all.

Let's leave basedir aside for a moment:

<lib> will put everything found under the given directory into
WEB-INF/lib (creating subdirectories you'll never be able to access if
dir points to a deeper structure).

<classes> will put everything found under the given directory into
WEB-INF/classes - the dir attribute should point to the root of a
class hierarchy.

<fileset> will simply put everything found into the war archive
without any leading directories. I hope this clear so far.

<war basedir="mydir" ... /> 

is the same as

<war ...>
  <fileset dir="mydir" />
</war>

Every file found in mydir (or anywhere down the directory starting
from basedir) will be added to the war archive with the path to
basedir stripped. <war> doesn't even try to ensure that things are not
included more than once.

Maybe the basedir attribute of <war> should be removed - forcing the
user to specify filesets for static content - to make the intent
clearer?

 MC> 3) Is there a way to specify a <fileset> that refers to a
 MC> directory that may or may not exist, without incurring an error
 MC> if it does not?

No. You could simply create empty directories using <mkdir> (which
will do nothing if the directory already exists) to achieve this.

Stefan