我有2个.wsdl文件和4个.xsd文件。 wsdl1
导入wsdl2
和wsdl2
导入所有4个xsd文件。
我在Eclipse Neon中有一个Gradle项目,想使用
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "src/main/resources/wsdl1.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) {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.6, target: 1.6, 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")
}
}
}
}
}
从wsdl文件生成Java类。它不起作用,但是Gradle将jaxb任务显示为绿色。如果我改为执行ext.schema = "src/main/resources/wsdl2.wsdl"
,则它会成功生成类,但是我缺少wsdl1
中的内容。
答案后编辑:
task generateJava {
inputs.file = "src/main/resources/wsdl1.wsdl"
outputs.dir = "${buildDir}/generated/java"
doLast {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir" ${buildDir}/generated/java"
xjc(destdir: file(${buildDir}/generated/java).absolutePath, schema: inputs) {
arg(value: "-wsdl")
produces(dir: outputs, includes: "**/*.java")
}
}
}
}
sourceSets.main.java {
srcDir "{$buildDir}/generated/java"
}
compileJava.dependsOn generateJava
抛出以下错误:No such property: file for class: org.gradle.api.internal.tasks.DefaultTaskInputs Possible solutions: files
答案 0 :(得分:0)
您并不是在以Gradle的方式思考。这是您应该做的:
例如:
apply plugin: 'java'
task generateJava {
inputs.file 'src/main/resources/mywsdl.wsdl'
outputs.dir "$buildDir/generated/java"
doLast {
mkdir "$buildDir/generated/java"
ant {
taskdef(name: 'xjc', ...)
xjc(destdir: "$buildDir/generated/java", ...) {
...
}
}
}
}
sourceSets.main.java {
srcDir "$buildDir/generated/java"
}
compileJava.dependsOn generateJava
答案 1 :(得分:0)
我遇到了完全相同的问题。多亏了本教程,它才有效! https://jaxenter.com/tutorial-gradle-soap-features-revealed-104493.html
简而言之,我没有使用xjc插件来创建Java类,而是使用了wsimport,它就像一个魅力。
configurations {
jaxws
}
task genWs {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = ""//source to your wsdl file here
outputs.dir classesDir
doLast() {
project.ant {
taskdef (name:'wsimport',
classname:'com.sun.tools.ws.ant.WsImport',
classpath:configurations.jaxws.asPath)
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
wsimport(keep:true,
destdir: classesDir,
sourcedestdir: sourcesDir,
wsdl: schema)
}
}
}
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
compileJava {
dependsOn genWs
}