On 04/01/2011, at 12:28 AM, Kolovos, Val (Orbitz) wrote:
> Hi,
>
> I'm running a problem with what experience tells me is a ClassLoader issue.
> I'm trying to use the HTTP Builder Groovy Module, but whenever I need to
> parse XML responses, I get the following exception:
> java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser.
>
> I've been able to create a very simple build.gradle file to reproduce the
> problem. Just running 'gradle -t' (using Gradle 0.9) results in the failure.
> Running with '-i' definitely shows the xerces jar in the dependency
> resolution.
>
> Any help would be greatly appreciated.
This is a problem with the (lack of) classloader isolation in Gradle.
The cause is that the Gradle implementation classes and their dependencies are
all visible to build scripts. One such dependency is the maven ant tasks. These
happen to bundle up NekoHTML in their jar (of course). This means that when
your script goes to load the NekoHTML parser, the classloaders attempt to load
it from the core classloader, where xercesImpl is not visible to it, and so you
get a NoClassDefFoundError.
Here is a work around which may work for you, if you're happy to use the
version of NekoHTML bundled with the maven-ant-tasks:
buildscript {
repositories { ... }
dependencies { ... }
def xerces = configurations.classpath.find {
it.name.startsWith('xercesImpl-') }
Project.class.classLoader.addURL(xerces.toURI().toURL())
}
We do plan to rework the classloader hierarchy for the Gradle 1.0-milestone-1
release, so that the Gradle implementation classes are not visible to the build
scripts.
>
> Thanks,
>
> Val
>
> buildscript {
> repositories {
> mavenCentral()
> }
> dependencies {
> classpath group: 'org.codehaus.groovy.modules.http-builder', name:
> 'http-builder', version: '0.5.1'
> }
> }
>
> p = new org.cyberneko.html.parsers.SAXParser();
--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz