问题
I am new to gradle. In my project, i have xsd files and i would like to generate java classes from that xsd (using xmlbeans only). How to do that in gradle.
I am using axis2 1.6.1, gradle, xmlbean 2.3.0` (JAXB is not an option in my current project).
回答1:
As far as I know, you can use the "xmlbeansPlugin" for this. Can't say now, whether it's possible to change the xmlbean's version to the older one.
All you need is to apply the plugin to your build script:
apply from: 'https://raw.github.com/rartavia/gradle-plugins/master/xmlbeansPlugin/xmlbeans.gradle'
Then declare xmlbeans
configuration and it's dependency
configurations {
xmlbeans
}
dependencies {
xmlbeans 'org.apache.xmlbeans:xmlbeans:2.5.0'
}
After that you have to specify the xsd files location
sourceSets {
schemas {
srcDir = 'src/main/schemas'
}
}
And now you can call compileXmlSchemas
task to generate classes
回答2:
I had to modify Stanislav's answer a bit to get the plugin working. Namely setting the sourceSets in the following manner:
sourceSets {
xmlbeans {
java {
srcDirs = ['dir/schema']
}
}
}
in case someone has the same problem.
回答3:
java -classpath xbean.jar org.apache.xmlbeans.impl.tool.SchemaCompiler
-src <OUTPUT_SOURCE_FOLDER>
-out <OUTPUT>.jar <SOURCE>.xsd
-compiler "javac.exe"
-javasource "1.5"
来源:https://stackoverflow.com/questions/37304634/how-to-generate-java-class-from-xsd-by-using-xmlbeans-in-gradle