<< Power ASP.NET 2.0 Programming | Home | Mr. Publisher, I Want To Read Your Online Megazine. But... >>

We Have an Ant Task, ...

... all you have to do is to copy these lines into your build.xml file:

<taskdef
  name="ejbdoclet"
  classname="xdoclet.modules.ejb.EjbDocletTask"
  classpathref="project.class.path"
/>

I have been dutifully doing this in every one of my build.xml files that needs the task. (Well, not only this one, but other tasks from other tools.) At first, it is novel and exciting, "Look, I just added a snippet of XML to build.xml, and it can do this!" But it's getting old now, especially on the one thousandth time: "What's the class name of that task? And which jar file is it in?" I've tried external entity references which only obscures the issue.

What I want is a way to tell my installation of Ant about any new Ant tasks that's avaiable in third party packages. Do it once. And have that task available to all Ant runs that use the installation, like any other task that come bundled with Ant.

There must be a way to do this that I missed.



Re: We Have an Ant Task, ...

add the jar file in the lib folder of ant home, and it will automatcially puck it up

Re: We Have an Ant Task, ...

That alone doesn't do the trick. You still have to do a taskdef in build.xml.

Re: We Have an Ant Task, ...

I can think of two possible "workarounds", although neither is perfect. First, you can edit "defaults.properties", a file inside of the ant.jar file. The drawback is you have to patch the JAR file with your customization. Also make sure the JARs for your custom task are copied to ANT_HOME/lib.

A second workaround is to put all of your taskdefs in a single Ant buildfile, then use the Ant import task to always import your taskdefs. It's still a single line of code you have to add to your buildfiles, but it is only a single line instead of multiple lines.

Re: We Have an Ant Task, ...

Thanks, Eric.

I like the first approach a lot better than the second one. It seems to me the file (org/apache/tools/ant/taskdefs/defaults.properties in ant.jar) is make for this purpose.

With the help of Emacs (one of two of my favorite editors, the other being vim), editing the file in ant.jar is no harder than editing a regular file.

Instead of making a copy of the jar file, I made a symbolic link. This saves some disk space. It also ensures that any future updates to the jar file (as long as the path and name is not changed) will be reflected in Ant. (Windows/NTFS does not support symbolic links, but does support hard links---one file showing up in two different directories. You can create hard links with the Cygwin ln command.)

A side effect of doing this is that when I ran the antstructure task, the new task's syntax shows up in ant.dtd. Now I can have command completion for the new tasks.

Re: We Have an Ant Task, ...

I dicussed a slight modification to your option #1 here: http://jroller.com/page/pmckinstry/20050209#we_have_an_ant_task

Re: We Have an Ant Task, ...

You can always place your defintion into a file named antlib.xml and use Ant's namespace support for antlibs. Or just <taskdef resource="..."/> if namespaces is too much.

Add a comment Send a TrackBack