ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: Problem with <antlr> task
Date Thu, 01 Feb 2001 05:52:35 GMT
At 11:08  1/2/01 +0530, NIkhil R. Deshpande wrote:
>> > When I put antlr.jar in %ANT_HOME%\lib directory and run
>> > ant, I get following exception:
>> > 
>> >     java.lang.NoClassDefFoundError: antlr/Tool
>> > 
>> 
>> but not if you use fork="no", right?
>
>I'm sorry, but with or without fork attribute, fork="no"  or "false"
>or "yes" or "true", all give the same exception.
>
>For the same setup, running antlr.Tool class through <java>
>task runs fine without any exceptions:
>
><java classname="antlr.Tool">
>          <arg value="-o"/>
>          <arg value="${build.dir}/${parser.pkg.dir}/antlr"/>
>          <arg value="src/parsergrammars/antlr_aliases.g"/>
></java>

yes this is an unfortunate side-effect of the way classloading works. The
antlr.jar has to be in the same classloader (or a parent) as the
optional.jar for the task to be able to "see" antlr classes. The above gets
around it by using the top-level classloader and not going via task class. 

I don't think there is a workaround for Ant1.x other that what you have
outlined (place antlr.jar in CLASSPATH or else load optional.jar from same
place as antlr.jar). In Ant2.x we will be able to use Java2s notion of
ContextClassLoader which will "fix" this issue.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Mime
View raw message