Commits

phanto  committed ff0487c

initial

  • Participants

Comments (0)

Files changed (4)

File build.gradle

+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'application'
+
+defaultTasks 'build'
+version = '1.0'
+sourceCompatibility = 1.7
+
+sourceSets {
+  main {
+    java {
+      srcDirs "src/main/generated"
+    }
+    resources {
+      srcDir "src/main/resources"
+    }
+  }
+}
+
+repositories {
+ mavenCentral()
+}
+
+configurations {
+ xjc
+}
+
+dependencies {
+ xjc group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: '2.2.4-1'
+}
+
+task createDirs () {
+
+delete propGeneratedDir
+new File(propGeneratedDir).mkdirs()
+}
+
+task xjc () {
+ ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.xjc.asPath)
+ 
+ ant.xjc(
+  destdir: 'src/main/generated',
+  package: 'test.jaxb.xdo',
+  removeOldOutput: true,
+  schema: 'src/main/resources/xmlschema.xsd'
+ )
+}
+
+xjc.dependsOn createDirs
+compileJava.dependsOn xjc

File gradle.properties

+propGeneratedDir=src/main/generated
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>phanto</groupId>
+	<artifactId>JaxbClassesFromXSD</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+
+	<dependencies>
+		<dependency>
+			<groupId>javax.xml.bind</groupId>
+			<artifactId>jaxb-api</artifactId>
+			<version>2.1</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.5.1</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>jaxb2-maven-plugin</artifactId>
+				<version>1.5</version>
+				<executions>
+					<execution>
+						<id>xjc</id>
+						<goals>
+							<goal>xjc</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+					<outputDirectory>src/main/generated</outputDirectory>
+					<schemaDirectory>src/main/resources</schemaDirectory>
+					<packageName>test.jaxb.xdo</packageName> <!-- The name of your generated source package -->
+					<clearOutputDir>true</clearOutputDir>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

File src/main/resources/xmlschema.xsd

+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:element name="child" type="child"/>
+
+  <xs:element name="parent" type="parent"/>
+
+  <xs:complexType name="parent">
+    <xs:sequence>
+      <xs:element name="firstName" type="xs:string" minOccurs="0"/>
+      <xs:element name="name2" type="xs:string" minOccurs="0"/>
+      <xs:element name="date1" type="xs:string" minOccurs="0"/>
+      <xs:element name="date2" type="xs:dateTime" minOccurs="0"/>
+      <xs:element name="children" minOccurs="0">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="children" type="child" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="child">
+    <xs:sequence>
+      <xs:element name="age" type="xs:int"/>
+      <xs:element name="name" type="xs:string" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:schema>
+