'Error when converting XSD to Java using jaxb
It has been some time since I used XSD, XML and JAXB. Now I'd like to use it again. Unfortunately I have a strange error that I cannot resolve.
Here is my build.gradle.
configurations {
jaxb
}
dependencies {
jaxb 'org.glassfish.jaxb:jaxb-xjc:2.3.6'
}
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
// that works!
// ext.schema = 'https://raw.githubusercontent.com/spring-guides/gs-producing-web-service/main/complete/src/main/resources/countries.xsd'
// that DOES NOT work!
ext.schema = 'https://cwe.mitre.org/data/xsd/cwe_schema_latest.xsd'
outputs.dir sourcesDir
doLast() {
project.ant {
taskdef(
name: 'xjc',
classname: 'com.sun.tools.xjc.XJCTask',
classpath: configurations.jaxb.asPath
)
mkdir(dir: sourcesDir)
xjc(destdir: sourcesDir, schema: schema)
}
}
}
My schema comes from Mitre https://cwe.mitre.org/data/xsd/cwe_schema_latest.xsd. The overall task should work as the result is fine for a different sample schema https://raw.githubusercontent.com/spring-guides/gs-producing-web-service/main/complete/src/main/resources/countries.xsd. Unfortunately I'm getting the following error when using the Mitre schema.
[ant:xjc] [ERROR] Property "Lang" is already defined. Use <jaxb:property> to resolve this conflict.
[ant:xjc] line 302 of http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd
[ant:xjc] [ant:xjc] [ERROR] The following location is relevant to the above error
[ant:xjc] line 303 of http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd
I did some research and I sounds like I have to use some custom binding. However I do not even find "Lang" in the XSD file.
Any ideas how I can generate the Java code? Thank you very much!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
