File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant build fail, sometimes 'cause ant forgets property 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 build fail, sometimes Watch "Ant build fail, sometimes New topic
Author

Ant build fail, sometimes 'cause ant forgets property

Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
Hi

I am getting the following build error, sometimes.
BUILD FAILED
C:\eclipse\workspace\ContinuousTesting\build.xml:55: C:\eclipse\workspace\ContinuousTesting\${lib.dir} not found.


Here is the build.properties file:
src.dir=./src
build.dir=./bin
lib.dir=./lib


I've added some output to check that I am not drunk



This is the whole task


Which I hope proves that I am not completely drunk.

What is my build.classpath? here:


And the thing is... it works sometimes. Sometimes it doesn't.
I am running this through eclipse.

What am I missing?


Don't be shy, be quiet!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Exactly where is line 55 in your build.xml? Exactly how did Ant get there? I ask because I have experienced similar things via an 'antcall' (properties set in the build script are not being propagated to the antcall). Try running with the -v option, that might give you a clue as to exactly where the problem is.


JBoss In Action
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

Note this was cross posted to stack overflow. I think Peter's question is spot on.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
Of course this was cross-posted :-) I use all the best forums...

Line 55 is the javac call
<javac srcdir="${src.dir}" destdir="${build.dir}" listfiles="no" debug="true" classpathref="build.classpath" fork="true" memoryInitialSize="128m" memoryMaximumSize="512m" />

edit:
If I clean the project via eclipse - the compile works. Otherwise, if I delete a class file or even entire bin folder manually - it fails.
The compile task is called from several tasks. In all cases it works fine if I clean the project via eclipse first.


Thanks for helping
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Are you running the Ant build from within Eclipse? I ask because Eclipse adds a bunch of settings to the build.

It sounds to me like your Ant build script is not very well written - deleting a class file, or not running a 'clean' should not effect the build's success.

Did you try using -v like I suggested?
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
Yes, I am running from eclipse.
edit2: -v option: where shall I add it? I guess the answer is 'from command line' and I'll try it asap. see next message


Sorry, I can write Java and C++ code, I can do a handstand... but ant is a bit of a mis(t)ery still (I can rant for long periods about such tools).

edit:
To make life easier (now that I've realised that in the long time I was gone from this forum - upload is supported :-)) I've uploaded the properties and the build.xml file.
Comments are welcome on other things as well... as I am just starting to grind my teeth against the
cannot upload as any format I choose is ignored


Thanks,
A'z
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
First: Here is the contents of my build.xml file. See how many faults you find :-)



Right, I've ran Ant from command line with the -v option.
Here are some things which ant reports as it starts


So you can see it initially complains about the missing lib.dir, it does load the properties file.
Then I see it is adding all expected classes to the build list
i.e.


And as a prize I get the following ant exception (which I fail to learn anything new from):
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
I have resolved this by realising that I better not have the build.dir, lib.dir and src.dir properties as properties. This should sit within the build.xml file

Thanks for your time.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Suggestion: Do not use back-slashes in paths in Ant - the back-slash is too often taken as an escape character.

The problem is that you load the properties file from within a target, but the classpath is initialized globally. Thus lines 19..26 are performed before lines 6..10. You should either do all initialization within targets (I prefer this for complicated build scripts) or load the properties file globally (not within a target). I usually always load the properties file globally.

However your decision to move the properties into the build script is the correct decision. All project-relative paths should be defined within the build script itself. Use the properties file for external directory locations and other settings that can change from machine to machine or user to user.

By the way, if you are new with Ant, grab Ant in Action - I have the first edition of that book and found it to be invaluable.
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
Thanks Peter!

I guess I got what I deserve.
I took an Ant build file written by someone else, and just ripped some parts apart.

I'll learn now how to initialize the classpath as part of a task, and load the properties globally.

Thanks for the link !

A'z
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant build fail, sometimes 'cause ant forgets property