aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant taskdef & classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant taskdef & classpath" Watch "Ant taskdef & classpath" New topic
Author

Ant taskdef & classpath

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I have a running but ugly build with a taskdef with classpath in it:

Before giving it to anybody else I wanted to make it more portable, so I used a property for the location of the class file. For now I have the properties defined at the top of the file. Now the taskdef says

It appears that the taskdef is being evaluated before the properties because Ant-v says

Is that really the problem? Can I force the order?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Ant file property definitions are done from top to bottom, and the first definition is the one that wins. In the case of taskdefs, the classpath of the task definition is set when the task is defined, then when the task is executed (further down the build.xml) any classpath for the execution of the task which is specified for the task is set. It's occasionally confusing that there are 2 different classpaths at work, but it makes sense when you sort things out.

In any case, for both classpaths, the details become frozen in stone at the time they are defined and do not change thereafter.

I hope that's what you were asking about, and I hope my reply makes sense!


Customer surveys are for companies who didn't pay proper attention to begin with.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I'm a little bit confused, because in your taskdef you seem to have a property "folder", but the Ant error message talks about a property "saxmanfolder". What am I missing? Can you show us more of your Ant code?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
D'oh! I'll check those names when I get home. I might have changed that first one to anonymize it a bit but ... I don't think so. I was reluctant to share the whole script because I definitely "paved the cowpath" and automated a bunch of steps that should have been elminiated instead.

The sequence should be good, I think ... the properties are all set at the top of the file, the task definition further down, task execution immediately after that.

BTW: The task generates a list of all packages in the source directory for the benefit of JavaDoc. There must be a standard way to do this, no? Here's from the old all-hard-coded script:
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Can't you simply use the nested packageset element?
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Tim Holloway wrote:Ant file property definitions are done from top to bottom, and the first definition is the one that wins. In the case of taskdefs, the classpath of the task definition is set when the task is defined, then when the task is executed (further down the build.xml) any classpath for the execution of the task which is specified for the task is set. It's occasionally confusing that there are 2 different classpaths at work, but it makes sense when you sort things out.


Hi Tim, I wanted to ask about how to set the classpath when the task is executed. Right now, I'm getting a NoClassDefFoundError when I try and run my custom task but this is mostly because I don't know how to set the classpath when I run the task. I do it like so



Any help is appreciated, - Dave
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Without checking with the Ant docs, I see that you're effectively declaring the classpath twice. Which method do the docs recommend?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi Martijn,

I'm not able to find any documentation on those two things online, but as far as I can tell, they do the same thing (I've tried running the task setting the attribute and then another variation setting the child element -- same result).

Can you address Tim's comment about the two classapaths (when task is defined and when task is executed)? It seems that both the things you were asking me about are related to defining the task but not executing the task.

Thanks, - Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant taskdef & classpath