You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eugene Kirpichov <ek...@gmail.com> on 2008/03/27 09:19:13 UTC

Ant profiler + Embedded ant classpath problems

Hi everybody,

1. I have written a line-level profiler for ant build scripts:
http://sourceforge.net/projects/antro . I was surprised at how easy it
was and at the fact that no one has done that before (at least, to my
best knowledge)

2. I was going to add a feature to launch ant script directly from the
GUI but I ran into problems with supplying extra classpath to ant. Is
there a working example (sized less than, say, 3kloc code) of doing
that or a troubleshooting guide for that?
There was a letter to this mailing list today about just embedding ant
in the application - I did that successfully, no big deal. However I
found no API in Project etc. like 'addClasspathElement()' and started
to play with classloaders.
First, I did the same thing as what is done in
org.apache.tools.ant.launcher.Launcher: I changed the system property
'java.classpath' and did Thread.currentThread().setContextClassLoader
with an URLClassLoader packed up with the extra classpath. That just
plain didn't work; ant didn't use that classloader for loading the
extra classes.
Then I tried to use AntClassLoader in the same way and launched the
build in a separate thread; that didn't work either, with a different
message but same meaning.
My suspection was that for loading the extra classpath Ant for some
reason uses not the classloader I gave him but Class.forName() or
project.getClass().getClassLoader().findClass().
Then I tried to create a Project object not with new Project() but
with that extra classloader and had to write a lot of things like
p.getClass().getMethod("fireBuildStarted").invoke(null).
In this case, I had class incompatibility problems between this
Project and objects I passed to  its methods (which I still created
manually). I didn't dare do _everything_ with the extra loader.

I did 3 or 4 more different attemts and finally gave up.

Well, the description above is rather lengthy and I unfortunately
didn't keep copies of all my attempts' sources to show you, so it may
be better if just someone told me 'To programmatically add extra
classpath to a project, do this and that' :)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org