gipoco.com
is neither affiliated with the authors of this page or responsible
for its contents. This is a safe-cache copy of the original web site.
gipoco.com
is neither affiliated with the authors of this page nor responsible
for its contents. This is a safe-cache copy of the original web site.
Ant: Debugging Classpaths
At 11:14 PM on May 1, 2006, R.J. Lorimer wrote:
Fresh Jobs for Developers Post a job opportunity
A lot of times when I'm working on an Ant build script, I'll run into compiler errors that I have no reason to believe are valid. You know the kind; you've written a script and you've set up all of your classpaths, and then you run the script and it starts complaining about classfiles missing that you *just know* are not missing.
This process can be a real pain to debug, particularly because Ant isn't exactly transparent in its running (Eclipse has the ability to debug an Ant script, but that's a different discussion). One technique I have used many, many times is to have Ant print out the classpath I'm getting ready to compile against so that I can see what class files, JAR files, and other minutia are actually on the classpath so that there is no doubt on my mind that the correct dependencies are being referenced.
To have Ant print out a classpath, you simply have to give your classpath a ref-id. This allows you to set up the correct variables later for printing. Here is an example. This is a snippet Ant file example that may look something similar to an ant script you have floating around:
If we wanted to debug the 'classpath' path attribute to make sure it had every JAR we anticipated, we could do this:
The
refid
attribute on theproperty
tag serializes the object with the given reference ID onto the property (in this case, our classpath).Note that after slinging together this tip, I also ran into this much more friendly version from Andrew Beacock's Blog: Pretty Printing Java Classpaths Using Ant's pathconvert Task . I wish I could take credit for this as it is much more fancy than mine .
Anyway, this proved to be an interesting problem that elicited help from several teams: JDT Core, Platform/JDT Text, JDT UI, and Platform/JDT Debug.
Until next time,
R.J. Lorimer
Contributing Editor -
rj -at- javalobby.orgAuthor -
www.coffee-bytes.comSoftware Consultant -
www.numbersix.com10 replies so far ( Post your own)
The real tip is: includeantruntime="false"
Interesting tip.However the biggest issue I've come across is the following:
The javac task *by default* has the 'includeantruntime' flag set to 'true' ! This IMHO is the stupidest thing the Ant developers ever did: The result is that all the librarys any ant task ever uses is part of the classpath during the compilation. This can lead to the weirdest errors you will ever see. Especially because in some configurations Ant has a mode so that any jar file that simply resides in the working directory where you invoke the ant call is automagically included to the ant classpath and thus included into the javac classpath (!).
So what I did is I did a "find in paths (e.g. find *.xml & grep javac)" for javac and make sure that includeantruntime="false" is specifiec for each javac task (only Ant developers and Ant task developers should ever need to set this to 'true').
I hope that for Ant 2.0 they remove this "feature".
'hope this helps other people as it helped me getting rid of the weirdest Ant javac classpath problems.
regards - Sebastian
Re: The real tip is: includeantruntime="false"
Sebastian,Is that true even when you set 'fork="true"'?
Regards,
Re: The real tip is: includeantruntime="false"
I just checked and it seems to me as if it is still true (just add an "import org.apache.tool.ant.Task;" to one of your sourcefiles and see whether it compiles through Ant) . It could be considered another bug/problem if the behavior was different depending on the fork setting.Regards, Sebastian
Re: The real tip is: includeantruntime="false"
and ant also includes the environmentsetting CLASSPATH !So I always edit the ant-scriptfile to set the CLASSPATH to ""
Re: Ant: Debugging Classpaths
I believe I also was able to see the contents of the classpath thru hover-text when debugging an ant script. That was a very pleasant surprise!Re: Ant: Debugging Classpaths
I do something similar but got tired of reading all the path separators so I created this macroHere is how you use it...
Here is one that works off of filesets
Usage:
Re: Ant: Debugging Classpaths
The good and interesting tip.Re: Ant: Debugging Classpaths
Very useful tip, but the splitting of the paths onto new lines didn't work for me. But this did:<pathconvert pathsep="${line.separator}" property="@{filesetref}.echopath">
Re: Ant: Debugging Classpaths
Thansk for the tip,I meet the same errors.Now I can fix it.
Re: Ant: Debugging Classpaths
Thansk for the tip,I meet the same errors.Now I can fix it. (same post.please delete this ,sorry)