Gradle JAXB WSDL任务失败,并出现java.lang.NoClassDefFoundError:javax / xml / bind / JAXBContext

时间:2018-10-23 12:42:01

标签: gradle jaxb wsdl

尽管已将jaxb-api定义为依赖项JAXBContext,但在执行任务genJaxb时找不到。添加jaxb-corejaxb-impl无效。

错误消息:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/user/IdeaProjects/idx/fmd/build.gradle' line: 19

* What went wrong:
Execution failed for task ':fmd:genJaxb'.
> java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext

build.gradle:


configurations {
    jaxb
}

task genJaxb {
    ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
    ext.classesDir = "${buildDir}/classes/jaxb"
    ext.schema = "x.wsdl"

    outputs.dir classesDir

    doLast() {
        project.ant {
            taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
                    classpath: configurations.jaxb.asPath
            mkdir(dir: sourcesDir)
            mkdir(dir: classesDir)

            xjc(destdir: sourcesDir, schema: schema,
                    package: "hello.wsdl") {
                arg(value: "-wsdl")
                produces(dir: sourcesDir, includes: "**/*.java")
            }

            javac(destdir: classesDir, source: 1.10, target: 1.10, debug: true,
                    debugLevel: "lines,vars,source",
                    classpath: configurations.jaxb.asPath) {
                src(path: sourcesDir)
                include(name: "**/*.java")
                include(name: "*.java")
            }

            copy(todir: classesDir) {
                fileset(dir: sourcesDir, erroronmissingdir: false) {
                    exclude(name: "**/*.java")
                }
            }
        }
    }
}

dependencies {
    compile "javax.xml.bind:jaxb-api:2.3.1"
    compile(files(genJaxb.classesDir).builtBy(genJaxb))

    jaxb "com.sun.xml.bind:jaxb-xjc:2.3.1"
}

环境:

  • Java 10.0.2
  • Gradle 4.10.2

1 个答案:

答案 0 :(得分:1)

有了此依赖项列表,构建终于成功了:


dependencies {
    compile(files(genJaxb.classesDir).builtBy(genJaxb))

    jaxb "com.sun.xml.bind:jaxb-xjc:2.3.1"
    jaxb "com.sun.xml.bind:jaxb-impl:2.3.1"
    jaxb "javax.xml.bind:jaxb-api:2.3.1"
    jaxb "org.glassfish.jaxb:jaxb-core:2.3.0.1"
}