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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Error Handling in ANT" Watch "Error Handling in ANT" New topic
Author

Error Handling in ANT

Anatoly Bondar
Greenhorn

Joined: Feb 18, 2005
Posts: 5
Hi,
I am trying to detect an error and write error and success log into the log files. I am new to ANT and having a big problem finding the right approach.
Please help. I have tried <FAIL>,etc and so far ..... no good.

thank you very much.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I'm not sure from your explanation what you are trying to do.

Below are some examples using fail task from ant manual:

[ February 20, 2005: Message edited by: Carol Enderlin ]
Anatoly Bondar
Greenhorn

Joined: Feb 18, 2005
Posts: 5
That's correct. HOwever, when I use <fail/> right after <sql> even if it is fine, it is failing. Seems like it goes there anyway. I am just trying to check, if something failed, wright into fail log, otherwize - success log.

hank you for any help.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Yes, if you put <fail/> in your build you are telling it to fail. There is some if/unless logic you can put in fail task but that only helps with the fail case, and unless you are having things not fail on errors I guess it wouldn't reach that.

What are you trying to accomplish with your success and fail logs? Unless you specify otherwise many (most?) tasks will halt the build when they fail. And some information is output about why it failed.

You need some confirmation that something succeeded and you aren't getting that? I'm not sure how to help when I don't understand what you are trying to accomplish.

You mentioned the sql task. It has an attribute "onerror" = Action to perform when statement fails: continue, stop, abort. Required = No, default "abort". I tried it out real quick. With the default setting I got this:

mySql:

BUILD FAILED
C:\_Work\java\build\build.xml:12: Class Not Found: JDBC driver org.database.jdbcDriver could not be loaded
Anatoly Bondar
Greenhorn

Joined: Feb 18, 2005
Posts: 5
All I am trying to accomplish is, when SQL for some reason failes(user_id or passowrd, etc.) programm will write the record in the log file.

Thanx
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
What log file and why isn't it writing it?
Anatoly Bondar
Greenhorn

Joined: Feb 18, 2005
Posts: 5
Just a regular txt file. It does writes, but if I do <fail> it writes always there. I am trying to catch the condition right after <SQL> get executed. I just need to write something like "Succes" or "Failed", but seems like I cann't catch it . Right after SQl it failes and kiks it out. I have triet to set some var. , etc.
Anatoly Bondar
Greenhorn

Joined: Feb 18, 2005
Posts: 5
Something like <try> and <catch> would be perfect.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Have you looked at the Listeners & Loggerssection of the Ant Manual. You might find something useful in there such as the Log4jListener.

Log4jListener
Passes build events to Log4j, using the full classname's of the generator of each build event as the category:

build started / build finished - org.apache.tools.ant.Project
target started / target finished - org.apache.tools.ant.Target
task started / task finished - the fully qualified classname of the task
message logged - the classname of one of the above, so if a task logs a message, its classname is the category used, and so on.
All start events are logged as INFO. Finish events are either logged as INFO or ERROR depending on whether the build failed during that stage. Message events are logged according to their Ant logging level, mapping directly to a corresponding Log4j level.

ant -listener org.apache.tools.ant.listener.Log4jListener
 
wood burning stoves
 
subject: Error Handling in ANT
 
Similar Threads
open a pdf inline using MIME in ie7
ANT and Log4J
App stops logging after 10 minutes
Error while creating java project on eclipse
Failed build : InstallTask cannot be found