Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to get Java POJOs, generated from schema files, to implement custom interfaces via maven plugins
<?xml version="1.0"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="../schema/yourSchemaFile.xsd">
<jxb:bindings node="//xs:complexType[@name='SomeElementNameFromYourSchemaFile']">
<inheritance:implements>com.your.pojos.CommonInterface</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<cxf.version>2.7.7</cxf.version>
<cxf.xjc.version>2.3.0</cxf.xjc.version>
</properties>
<build>
<plugins>
<!-- Used to generate source code based on XSD (schema) file -->
<!-- http://cxf.apache.org/cxf-xjc-plugin.html -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>${cxf.xjc.version}</version>
<configuration>
<extensions>
<extension>org.jvnet.jaxb2_commons:jaxb2-basics:0.6.4</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-xsd-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/cxf-xjc/</sourceRoot>
<xsdOptions>
<xsdOption>
<xsd>${basedir}/src/main/resources/schema/yourSchemaFile.xsd</xsd>
<bindingFile>${basedir}/src/main/resources/bindings/customBindingFile.xjb</bindingFile>
<packagename>com.your.pojos</packagename>
<extension>true</extension>
<extensionArgs>
<extensionArg>-Xinheritance</extensionArg>
</extensionArgs>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
+ your-project-folder
- pom.xml
+ src
+ main
+ resources
+ bindings
- customBindingFile.xjb
+ schema
- yourSchemaFile.xjb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment