Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lachoy (1663)


I am actually Chris Winters; I am actually living in Pittsburgh, Pennsylvania, USA; I am actually married and have three cats. (Guess what one of them is named?) I am the "OpenInteract" guy, which could be good or bad.

Journal of lachoy (1663)

Thursday December 16, 2004
05:11 PM

Careful when using properties files to specify Ant taskdefs

[ #22340 ]

This is so trivial that I'm hesitant to post it. But it might save someone a few minutes. Short version: be sure to end any external taskdef declarations in a properties file with newlines.

Long version:

When using custom Ant tasks you have the option of specifying the name and class of the task in the <taskdef> tag:

<taskdef name="mytask"

You can then reference this task like any built-in Ant task:

<mytask myOption="foo" myOtherOption="${bar}" />

Easy enough. But there's another way to declare a task:

<taskdef resource="">
    <classpath refid="some.classpath.ref" />

The referenced properties file ( ) is a simple name-to-class mapping like you'd expect:

# Ant automatically makes these tasks available
mytask    = com.mydomain.MyTask
othertask = com.mydomain.OtherTask

And when Ant reads this in it loads the referenced classea and makes taskdefs available under the given names. Very useful for building task libraries, and pretty simple. But if the last line does not end in a newline Ant will die with something like:

.../build.xml:84: The following error occurred while executing this line:
.../build.xml:123: taskdef class com.mydomain.MyTask   cannot be found

If you have any experience with Ant your first instinct will be to check your classpath reference, make sure you don't have any typos or pointers to out-of-date JARs, whatever. Resist that urge, and first make sure your properties file has at least one trailing newline. (Sidenote: One of my sayings is: "When dealing with hardware, 90% of the time the problem is the cables." So: "When dealing with Ant, 90% of the time the problem is the paths." Except this time.)

Posted from; read original

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.