Jaxp问题?Can';t使用gradle查找org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

Jaxp问题?Can';t使用gradle查找org.apache.xerces.jaxp.DocumentBuilderFactoryImpl,gradle,jaxp,Gradle,Jaxp,我很难在gradle脚本中加载类。当我运行此代码时: buildscript { repositories { mavenCentral() } dependencies { classpath( group:"xerces", name:'xercesImpl', version:'2.9.1') } } task hello { doLast { println 'Hello world!'

我很难在gradle脚本中加载类。当我运行此代码时:

buildscript {
    repositories {
       mavenCentral()
    }
    dependencies {
        classpath( group:"xerces", name:'xercesImpl', version:'2.9.1')
    }
}

task hello {
    doLast {
        println 'Hello world!'
        Class testClass = Class.forName("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl")
        assert testClass: "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found"
        println "found"
    }
}
当我运行“gradle hello”时,我得到了这个消息: java.lang.ClassNotFoundException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl“

我怀疑Jaxp的实现问题,但不太了解Jaxp是如何工作的


谢谢你的帮助

这样的东西够了吗

import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;

buildscript {
    repositories {
       mavenCentral()
    }

    dependencies {
        classpath group:"xerces", name:'xercesImpl', version:'2.9.1'
    }
}

task hello {
        println 'Hello world!'
        DocumentBuilderFactoryImpl obj = new DocumentBuilderFactoryImpl()
        // do something with obj
}
请尝试
getClass().getClassLoader()
Class.forName()
根本不应该使用;它在从Java调用时存在已知问题,在从Groovy调用时完全不可靠(通常会得到Groovy库的类加载器,而不是调用方的类加载器)