Created
January 23, 2015 08:31
-
-
Save marcellodesales/dbb9baf0c0214a4b84e8 to your computer and use it in GitHub Desktop.
Java POJO Code Generation from XSD using Gradle 2.1 (See gradle xjc screen below)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
maven { url "https://repo.spring.io/libs-release" } | |
mavenLocal() | |
mavenCentral() | |
} | |
dependencies { | |
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.10.RELEASE") | |
//####################### XJC - JDK 1.7/1.8 #################### | |
classpath 'com.github.jacobono:gradle-jaxb-plugin:1.3.5' | |
//###################### | |
} | |
} | |
apply plugin: 'java' | |
apply plugin: 'eclipse' | |
apply plugin: 'idea' | |
apply plugin: 'spring-boot' | |
//####################### XJC - JDK 1.7/1.8 #################### | |
apply plugin: 'com.github.jacobono.jaxb' | |
//###################### | |
jar { | |
baseName = 'gs-rest-service' | |
version = '0.1.0' | |
} | |
repositories { | |
mavenLocal() | |
mavenCentral() | |
maven { url "https://repo.spring.io/libs-release" } | |
} | |
dependencies { | |
//####################### XJC - JDK 1.7/1.8 #################### | |
jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41' | |
jaxb 'com.sun.xml.bind:jaxb-impl:2.2.7-b41' | |
jaxb 'javax.xml.bind:jaxb-api:2.2.7' | |
//###################### | |
compile("org.springframework.boot:spring-boot-starter-web") | |
testCompile("junit:junit") | |
} | |
//####################### XJC - JDK 1.7/1.8 #################### | |
jaxb { | |
xjc { | |
xsdDir = "src/main/resources/schema" | |
generatePackage = "com.intuit.platform.service.formsavailability.domain" | |
} | |
} | |
//###################### | |
task wrapper(type: Wrapper) { | |
gradleVersion = '1.11' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git status . | |
On branch master | |
Changes not staged for commit: | |
(use "git add <file>..." to update what will be committed) | |
(use "git checkout -- <file>..." to discard changes in working directory) | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityForm.java | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityFormset.java | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityPlatform.java | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityProduct.java | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/FormsAvailability.java | |
modified: src/main/java/com/intuit/platform/service/formsavailability/domain/ObjectFactory.java | |
--- a/src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityForm.java | |
+++ b/src/main/java/com/intuit/platform/service/formsavailability/domain/AvailabilityForm.java | |
@@ -1,8 +1,8 @@ | |
// | |
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 | |
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.7-b41 | |
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> | |
// Any modifications to this file will be lost upon recompilation of the source schema. | |
-// Generated on: 2015.01.22 at 11:20:47 PM PST | |
+// Generated on: 2015.01.23 at 12:12:55 AM PST | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mdesales@ubuntu [01/23/2015 0:12:22] ~/dev/github-intuit/mdesales/service-forms-availability (master *) $ gradle xjc | |
:xsd-dependency-tree | |
jaxb: starting Namespace Task | |
There is no targetNamespace attribute for file '/home/mdesales/dev/github-intuit/mdesales/service-forms-availability/src/main/resources/schema/formsAvailability.xsd' (assigning filname as namespace to it). A Schema should ALWAYS include a targetNamespace attribute at its root element. No targetNamespace are categorized as using the Chameleon Design Pattern, which is not an advisable pattern, AT ALL! | |
jaxb: generating xsd namespace dependency tree | |
:xjc | |
Download https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-xjc/2.2.7-b41/jaxb-xjc-2.2.7-b41.pom | |
Download https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.2.7-b41/jaxb-impl-2.2.7-b41.pom | |
Download https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api/2.2.7/jaxb-api-2.2.7.pom | |
Download https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-xjc/2.2.7-b41/jaxb-xjc-2.2.7-b41.jar | |
Download https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.2.7-b41/jaxb-impl-2.2.7-b41.jar | |
Download https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api/2.2.7/jaxb-api-2.2.7.jar | |
BUILD SUCCESSFUL | |
Total time: 13.758 secs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xs:schema | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
elementFormDefault="unqualified"> | |
<xs:element name="formsavail" type="FormsAvailability" /> | |
<xs:complexType name="FormsAvailability"> | |
<xs:sequence> | |
<xs:element name="platform" type="AvailabilityPlatform" maxOccurs="unbounded" /> | |
</xs:sequence> | |
<xs:attribute name="timestamp" use="required" type="xs:string" /> | |
</xs:complexType> | |
<xs:complexType name="AvailabilityPlatform"> | |
<xs:sequence> | |
<xs:element name="product" type="AvailabilityProduct" maxOccurs="unbounded" /> | |
</xs:sequence> | |
<xs:attribute name="type" use="required" type="xs:string" /> | |
</xs:complexType> | |
<xs:complexType name="AvailabilityProduct"> | |
<xs:sequence> | |
<xs:element name="formset" maxOccurs="unbounded" type="AvailabilityFormset" /> | |
</xs:sequence> | |
<xs:attribute name="type" use="required" type="xs:string" /> | |
</xs:complexType> | |
<xs:complexType name="AvailabilityFormset"> | |
<xs:sequence> | |
<xs:element name="form" type="AvailabilityForm" maxOccurs="unbounded" /> | |
</xs:sequence> | |
<xs:attribute name="formsetid" use="required" type="xs:string" /> | |
<xs:attribute name="prod" use="required" type="xs:string" /> | |
</xs:complexType> | |
<xs:complexType name="AvailabilityForm"> | |
<xs:attribute name="formid" use="required" type="xs:string" /> | |
<xs:attribute name="id" use="required" type="xs:integer" /> | |
</xs:complexType> | |
</xs:schema> |
Nice instructions. I changed the classes to reside in generated dir. Then add that to the main src set. Keep the main src set clean
jaxb {
xjc {
xsdDir = "src/main/resources/schema"
destinationDir = "src/generated/java"
generatePackage = "com.shane.alycon.raidr.xml.undertakr"
}
}
sourceSets {
main {
java {
srcDir 'src/generated/java'
}
}
}
Thanks shavo007, nice tips
Hi shavo007 this code is not working for me...it is not generating java class
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full Instructions
You can customize Gradle to generate the source before compiling the classes.
😄