首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jaxp问题?使用gradle找不到org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

Jaxp问题?使用gradle找不到org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
EN

Stack Overflow用户
提问于 2011-05-14 11:52:09
回答 2查看 1.5K关注 0票数 0

我在gradle脚本中加载类时遇到了问题。当我运行这段代码时:

代码语言:javascript
复制
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“时会得到这样的结果: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl”:java.lang.ClassNotFoundException

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

谢谢你的帮助

EN

回答 2

Stack Overflow用户

发布于 2011-05-16 08:27:51

像这样的东西足够了吗?

代码语言:javascript
复制
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
}
票数 0
EN

Stack Overflow用户

发布于 2011-05-31 14:39:28

请尝试使用getClass().getClassLoader()。根本不应该使用Class.forName();它在从Java调用时存在已知问题,并且在从Groovy调用时完全不可靠(通常会得到Groovy库的类加载器,而不是调用者的类加载器)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5999703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档