0

クラスを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"
    }
}

「gradlehello」を実行すると、これが発生します:java.lang.ClassNotFoundException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl "

Jaxpの実装の問題が疑われますが、jaxpがどのように機能するかについてはよくわかりません。

助けてくれてありがとう

4

2 に答える 2

0

このようなもので十分でしょうか?

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
}
于 2011-05-16T00:27:50.583 に答える
0

getClass().getClassLoader()代わりに試してください。Class.forName()まったく使用しないでください。Java から呼び出された場合には既知の問題があり、Groovy から呼び出された場合はまったく信頼できません (通常、呼び出し元のクラス ローダーではなく、Groovy ライブラリのクラス ローダーを取得します)。

于 2011-05-31T06:39:27.650 に答える