Define Document Type in plain XML for Nuxeo - nuxeo

I try to grasp the mechanics of Nuxeo and as such started with all tutorials and documents around. I put together a bundle that seemed quite right for me and tried now for several hours to make it work in any flavor - without success.
Using Nuxeo 8.3.
Anything i am missing?
The manifest at META_INF/MANIFEST.MF
Manifest-Version: 1.0
Bundle-SymbolicName: de.foo.nuxeo.tutorial.tutorial-demo1;singlet
on=true
Bundle-Version: 1.0.0
Bundle-Name: tutorial-demo1
Bundle-ClassPath: .
Bundle-ManifestVersion: 2
Bundle-Vendor: de.foo.nuxeo.tutorial
Nuxeo-Component: OSGI-INF/foo-demo-component-core-types.xml,OSGI-INF/foo-demo-component-ui-types.xml
A core document type at OSG-INF/foo-demo-component-core-types.xml
<?xml version="1.0"?>
<component name="de.foo.demo.component.core.types" version="1.0">
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="foo" src="schemas/foo-demo-foo.xsd"
prefix="isfoo" />
</extension>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype" >
<doctype extends="File" name="FooFile">n
<schema name="foo" />
</doctype>
</extension>
</component>
A ECM document type at OSGI-INF/foo-demo-component-ui-types.xml
<?xml version="1.0"?>
<component name="de.foo.demo.component.ui.types" version="1.0">
<require>org.nuxeo.ecm.platform.types</require>
<extension target="org.nuxeo.ecm.platform.types.TypeService"
point="types">
<type id="FooFile">
<label>Foo File</label>
<icon>/icons/file.gif</icon>
<bigIcon>/icons/file_100.png</bigIcon>
<category>SimpleDocument</category>
<description>A foo file</description>
<default-view>view_documents</default-view>
<layouts mode="any">
<layout>heading</layout>
<layout>file</layout>
</layouts>
</type>
<type id="Folder">
<subtypes>
<type>FooFile</type>
</subtypes>
</type>
</extension>
</component>
A schema at schemas/foo-demo-foo.xsd
<?xml version="1.0"?>
<xs:schema
targetNamespace="http://www.foo.de/nuxeo/schemas/foo/"
xmlns="http://www.foo.de/nuxeo/schemas/foo/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="gnu" type="xs:string" />
<xs:element name="gnat" type="xs:string" />
</xs:schema>
Packed in a jar and deployed to nxserver/bundles. After a restart i see the bundle loaded in the administrator view, no errors in the log file. When i create a new document, i do not see the new type...
What am i missing?

Related

JAXB xjc class generation - recursive element/namespace collisions

I'm trying to generate classes for the ECMA-376 v5 schemas, but can't fix a collision of two elements via bindings customization, i.e. it will throw an [ERROR] Two declarations cause a collision in the ObjectFactory class error.
To try it yourself, just put the below ant build and the bindings file in a directory and call "ant" to setup and generate the classes.
If you uncomment the "Fixme" line in the ooxml.xjb, the generation will succeed, but looking at the src/org/openxmlformats/schemas/wordprocessingml/_2006/main/ObjectFactory.java you'll find the "Fixme" element is generated differently and probably doesn't make sense. So maybe use it just as a hint for your fix.
I guess the error is caused by the multiple "r" elements/references in ...:
wml.xsd->CT_RunTrackChange->EG_ContentRunContent->r
wml.xsd->CT_RunTrackChange->shared-math.xsd->EG_OMathMathElements->r
shared-math.xsd->EG_OMathElements->EG_OMathMathElements->r
shared-math.xsd->EG_OMathElements->wml.xsd->EG_PContentMath->EG_ContentRunContentBase->EG_RunLevelElts->EG_MathContent->shared-math.xsd->oMath->CT_OMath->EG_OMathElements... (see 3/4)
Although there are references on SO, that -XautoNameResolution would help, this seems to be futile in my case.
If nothing helps, I probably will search/replace the fixme tokens after generation, but I guess the correct binding instructions are not far away ...
In case you wonder why I use Moxy. This is a prototype for Apache POI and Moxy is suitable for android-conversion and license compatible - in any case I aim for a solution which preserves the XML infoset.
build.xml:
<project name="ECMA v5 xjc" default="doit" basedir=".">
<!-- the repository to download jars from -->
<property name="repository.m2" value="https://repo1.maven.org"/>
<property name="jaxb-dir" location="lib"/>
<property name="dist.jaxb-xjc.url" value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-xjc/2.3.0/jaxb-xjc-2.3.0.jar"/>
<property name="dist.jaxb-xjc.jar" value="${jaxb-dir}/jaxb-xjc-2.3.0.jar"/>
<property name="dist.jaxb-core.url" value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-core/2.3.0/jaxb-core-2.3.0.jar"/>
<property name="dist.jaxb-core.jar" value="${jaxb-dir}/jaxb-core-2.3.0.jar"/>
<property name="dist.jaxb-api.url" value="${repository.m2}/maven2/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar"/>
<property name="dist.jaxb-api.jar" value="${jaxb-dir}/api/jaxb-api-2.3.0.jar"/>
<property name="dist.eclipselink.url" value="${repository.m2}/maven2/org/eclipse/persistence/eclipselink/2.7.0/eclipselink-2.7.0.jar"/>
<property name="dist.eclipselink.jar" value="${jaxb-dir}/eclipselink-2.7.0.jar"/>
<property name="dist.moxy.url" value="${repository.m2}/maven2/org/eclipse/persistence/org.eclipse.persistence.moxy/2.7.0/org.eclipse.persistence.moxy-2.7.0.jar"/>
<property name="dist.moxy.jar" value="${jaxb-dir}/org.eclipse.persistence.moxy-2.7.0.jar"/>
<property name="dist.ooxml_v5.url" value="https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-376,%20Fifth%20Edition,%20Part%204%20-%20Transitional%20Migration%20Features.zip"/>
<property name="dist.ooxml_v5.jar" value="${jaxb-dir}/ooxml_v5-all.zip"/>
<property name="dist.xmlxsd.url" value="http://www.w3.org/2001/03/xml.xsd"/>
<property name="dist.xmlxsd.xsd" value="${jaxb-dir}/xml.xsd"/>
<macrodef name="downloadfile">
<attribute name="src"/>
<attribute name="dest"/>
<sequential>
<get src="#{src}" dest="#{dest}" skipexisting="true"/>
</sequential>
</macrodef>
<target name="doit">
<mkdir dir="src"/>
<mkdir dir="${jaxb-dir}/api"/>
<mkdir dir="${jaxb-dir}/ooxml_v5"/>
<mkdir dir="${jaxb-dir}/episodes_v5"/>
<downloadfile src="${dist.jaxb-xjc.url}" dest="${dist.jaxb-xjc.jar}"/>
<downloadfile src="${dist.jaxb-core.url}" dest="${dist.jaxb-core.jar}"/>
<downloadfile src="${dist.jaxb-api.url}" dest="${dist.jaxb-api.jar}"/>
<downloadfile src="${dist.eclipselink.url}" dest="${dist.eclipselink.jar}"/>
<downloadfile src="${dist.moxy.url}" dest="${dist.moxy.jar}"/>
<downloadfile src="${dist.ooxml_v5.url}" dest="${dist.ooxml_v5.jar}"/>
<downloadfile src="${dist.xmlxsd.url}" dest="${dist.xmlxsd.xsd}"/>
<unzip dest="${jaxb-dir}" src="${dist.ooxml_v5.jar}">
<patternset>
<include name="OfficeOpenXML-XMLSchema-Transitional.zip"/>
</patternset>
<mergemapper to="ooxml_v5.zip"/>
</unzip>
<unzip dest="${jaxb-dir}/ooxml_v5" src="${jaxb-dir}/ooxml_v5.zip"/>
<!-- the DOCTYPE is causing problems with generating the schema classes -->
<copy tofile="${dist.xmlxsd.xsd}.edit" file="${dist.xmlxsd.xsd}">
<filterchain>
<linecontains negate="true">
<contains value="DOCTYPE"/>
</linecontains>
</filterchain>
</copy>
<move file="${dist.xmlxsd.xsd}.edit" tofile="${dist.xmlxsd.xsd}"/>
<java fork="true" classname="org.eclipse.persistence.jaxb.xjc.MOXyXJC">
<classpath>
<fileset dir="${jaxb-dir}" includes="*.jar"/>
</classpath>
<jvmarg value="-Djava.endorsed.dirs=${jaxb-dir}/api"/>
<!-- auto resolution is ignored ... -->
<arg value="-XautoNameResolution"/>
<arg value="-no-header"/>
<arg value="-extension"/>
<!--arg value="-verbose"/-->
<arg line="-episode ${jaxb-dir}/episodes_v5/step1.episodes"/>
<arg line="-b ooxml.xjb"/>
<arg line="-d src"/>
<arg value="${dist.xmlxsd.xsd}"/>
<arg value="${jaxb-dir}/ooxml_v5/shared-math.xsd"/>
<arg value="${jaxb-dir}/ooxml_v5/dml-main.xsd"/>
</java>
</target>
</project>
ooxml.xjb:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:math="http://schemas.openxmlformats.org/officeDocument/2006/math"
extensionBindingPrefixes="xjc">
<globalBindings generateIsSetMethod="true"/>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/officeDocument/2006/math">
<bindings scd="~tns:CT_R/model::sequence">
<bindings scd="tns:rPr">
<factoryMethod name="rPrMath"/>
</bindings>
<bindings scd="model::choice/tns:t">
<factoryMethod name="tMath"/>
</bindings>
</bindings>
<!--bindings scd="group::math:EG_OMathMathElements/model::choice/math:r">
<property name="rMath1"/>
</bindings-->
</bindings>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
<bindings scd="~tns:CT_Anchor/model::sequence/tns:simplePos">
<property name="simplePosList"/>
</bindings>
</bindings>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<!--bindings scd="~tns:CT_RunTrackChange/model::choice/group::math:EG_OMathMathElements/model::choice/math:r">
<class name="CTR" implClass="org.openxmlformats.schemas.officedocument._2006.math.CTR"/>
</bindings-->
<bindings scd="~tns:CT_RunTrackChange/model::choice/group::tns:EG_ContentRunContent/model::choice/tns:r">
<!--class name="FixmeR"/-->
</bindings>
</bindings>
</bindings>

jaxb multiple class generated for same type incase of external bindings

I have following schema and corresponding bindings file. I use jaxb2 maven plugin to generate JAXB classes.
person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="pType" type="pType" minOccurs="0" />
<xs:element name="sex" type="xs:string"
minOccurs="1" />
<xs:element name="dob" type="xs:string"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- some more elements ignored for clarity.................
.......................... -->
<xs:complexType name="pType">
<xs:sequence>
<xs:element name="category" type="xs:string"
minOccurs="0" />
<xs:element name="blahh" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
jaxb bindings
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings node="//xs:complexType[#name='pType']">
<jxb:class name="PersonType" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings
node="//xs:element[#name='person']//xs:element[#name='pType']">
<jxb:class ref="PersonType" />
</jxb:bindings>
</jxb:bindings>
I have defined bindings to override the name for the <xs:complexType name="pType"> as PersonType. On XJC generation, it generates PersonType.class and PType.class.
If I define <xs:complexType name="pType"> internally inside the element <xs:element name="pType" > then it did not generate PType.class.
But I have to declare <xs:complexType name="pType"> at the root level in schema, because this xs:complexType is referenced by other schemas as well.
I tried to override for both <xs:complexType name="pType"> and <xs:element name="pType" > in bindings and yet the PType.class gets generated.
How could I instruct it not to generate PType.class ?
The problem was that I have 2 executions for each of the schemas (dependent schema person2.xsd and person.xsd) in maven-jaxb2-plugin. So I had manually written the episode file to reference the already created <xs:complexType name="pType"> and resolved the issue.
For the benefit of someone who has same problem, here are the plugin execution details and episode file. Please note that I did not use namespaces hence you find the scd is simple without namespace.
person-episode
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="/type::pType">
<jaxb:class ref="org.wipo.pct.test.PersonType"/>
<jaxb:package name="org.wipo.pct.test" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
pom.xml
<execution>
<id>person</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>person2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person2.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings2.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
<args>
<arg>-b</arg>
<arg>src/main/resources/person-episode</arg>
<arg>-Xsimplify</arg>
<arg>-Xinheritance</arg>
</args>
</configuration>
</execution>

wsdl with conflicting xsd imports

I tried to find a solution for some time to the following problem. I have a wsdl file containing several (6) xsd imports. I cannot change these xsd's because they are external to my project. There are 4 definitions all together which are slightly defined different in 2 of these schemas. I was attempting to translate each 'conflicting' xsd schema to it's own package. I tried following bindings, but it did not do the job:
testbindings.jaxb:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
<bindings schemaLocation="a.xsd">
<schemaBindings>
<package name="org.wsi.a" />
</schemaBindings>
</bindings>
</bindings>
using: wsimport -p org.wsi -b testbindings.jaxb broker.wsdl
All classes are generated in org.wsi and no classes in org.wsi.a. Without the -p switch all xsd are generated in their own default package. But could not tell wsimport to use specific packages for each xsd. At this moment I use following binding file, which is probably incorrect, but for which the wsimport doesn't complain:
<?xml version="1.0"?>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxws:bindings wsdlLocation="broker.wsdl" node="wsdl:definitions/wsdl:types/xsd:schema">
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/b-2']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.b_2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/t-1']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.t_1"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxws:bindings>
In packages org.broker.wsi.b_2 and org.broker.wsi.t_1, no files are generated.
I used bindings as specified in: http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv/data_types.html#wp227713 but probably incorrect.
Suggestions are welcome.
The problem of setting up the correct package names for the wsdl, the internal xsd and the external xsd's is described in question/answer:
wsimport - how to generate service endpoint classes and JAXB classes in separate projects/folders, posted by:
dma-k
int-bindings.xml file:
<?xml version="1.0"?>
<jaxws:bindings version="2.0"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
wsdlLocation="broker.wsdl">
<jaxws:package name="org.broker.wsi" />
<jaxb:bindings node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.al"/>
</jaxb:schemaBindings>
</jaxb:bindings>
The external-bindings file (abbreviated):
<jaxb:bindings version="1.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="http://docs.oasis-open.org/wsn/b-2.xsd" node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.oasis.b2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>

JAXB External Custom Binding XJC Issue - Parsing results in empty node

Forgive me if this is a duplicate. Here is my binding.xjb file. But now i am getting the regular error that the complex type target "AddBankVaultRplyType" is not found. I don't see any issue. Can somebody help me with this? I am listing the xsd that i am trying to customize
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
jxb:version="2.1"
>
<jxb:bindings node="/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
Here is the piece of XSD that i am trying to customize
<xs:schema xmlns:pd="http://com/polsvc/xmlobj" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://com/polsvc/xmlobj" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="AddBankVaultRplyType">
</xs:complexType>
<xs:element name="ServiceReply">
<xs:complexType>
<xs:sequence>
<xs:element name="ReplyHeader" type="pd:MsgHeaderType"/>
<xs:element name="RequestHeader" type="pd:MsgHeaderType"/>
<xs:choice>
<xs:element name="AddBankVaultReply" type="pd:AddBankVaultRplyType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Now if i run XJC it is saying me that the target "/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']" results in empty node. What is the mistake i am doing here
You will need to wrap in a bindings that has the schema location set. It should be something like:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
For more information:
http://jaxb.java.net/guide/Dealing_with_errors.html
I finally got mine workign with subclassing as well as adding #XmlRootElement to those dang complexTypes that are used by a root element(I don't get why JAXB doesn't add it for me, but this does the trick of doing that since JAXB doesn't)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://annox.dev.java.net "
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:globalBindings>
<jaxb:serializable uid="1"/>
<!-- All generated classes must have MySignature interface (supplied in dependencies) -->
<xjc:superClass name="com.cigna.framework.DataObject"/>
<xjc:superInterface name="com.cigna.framework.InterfaceTest"/>
<!-- All temporal fields are implemented as Joda DateTime and use DateUtils as an adapter -->
<jaxb:javaType
name="org.joda.time.DateTime"
xmlType="xs:time"
parseMethod="com.cigna.framework.util.DateUtil.stringToDateTime"
printMethod="com.cigna.framework.util.DateUtil.dateTimeToString"
/>
</jaxb:globalBindings>
<!-- Application of annotations to selected classes within schemas -->
<!-- org.example.SomeRootType #XmlRootElement -->
<jaxb:bindings schemaLocation="../schemas/externalaction_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.action"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/common_2012_04.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.common"></jaxb:package>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='PersonNameType']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SomeRootType"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/utilities_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.util"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Of course I struggled with the pom.xml alot but finally came to this solution which worked for me.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>process-xsd</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<schemaIncludes>
<include>schemas/*.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>schemas/*.xjb.xml</include>
</bindingIncludes>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.3</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
later,
Dean

Compiling multiple schemas into different packages using JAXB 2.1

I have a CommonTypes.xsd which I'm including in my all other XSDs using xs:include. I get
Multiple <schemaBindings> are defined for the target namespace ""
when I try to compile it into different packages using binding files. Please tell me whether there is a way to compile them into different packages. I'm using jaxb 2.1
Yeah, there is a way.
Assuming:
xsd/common/common.xsd
xsd/foo/foo.xsd
In the common directory place common.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.common">
</jxb:package>
</jxb:schemaBindings>
In the foo directory place foo.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.foo">
</jxb:package>
</jxb:schemaBindings>
In the build.xml file, create one xjc task for each:
<xjc destdir="${app.src}" readOnly="true" package="mypkg.common">
<schema dir="${app.schema}/common" includes="*.xsd" />
<binding dir="${app.schema}/common" includes="*.xjb" />
</xjc>
<xjc destdir="${app.src}" readOnly="true" package="mypkg.foo">
<schema dir="${app.schema}/foo" includes="*.xsd" />
<binding dir="${app.schema}/foo" includes="foo.xjb" />
</xjc>
You need to make sure that common.xsd has a targetNameSpace that is different from foo.xsd's targetNameSpace.
As stated already by Ben there is no way to do that if they have the same namespace.
But how to do it if you do have different namespaces?
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.udt"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/codelists" schemaLocation="oagi/Common/OAGi/Components/CodeLists.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.cl"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
but be sure you do not use the command line parameter -p, since that will override your config.
I've meet the same problem and haven't solve it yet, but I'm afraid that it can't be possible to generate XSD into differents packages :
It is not legal to have more than one <jaxb:schemaBindings> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages
from Compiler Restrictions at the end of this page
but if some one find some work around, just inform us please
I know it is an old post, but, as there is no answer for the exact question, here is my proposal:
As mmoossen explained, the trick is to specify different namespaces for the XSDs.
But, adding a namespace attribute in the jxb:bindings tag doesn't work:
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
Instead of that, you need to add a targetNamespace attribute to the xs:schema tags of your XSDs:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="some.namespace"
version="1.0">
Once done, you will be able to have 1 external customization file (.xjb) declaring different schemaBindings, each of them possibly using a different package:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox inherit">
<jaxb:bindings schemaLocation="MyFirstXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.a" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MySecondXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.b" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MyThirdXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.c" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Can be done as mentioned in jaxb maven plugin usage page in case of having Multiple schemas with different configuration.
Separate packages can be configured for each schema.
<packageName>se.west</packageName>
complete example configuration below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>xjc-schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the west directory for sources here. -->
<sources>
<source>src/main/xsds/west</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.west</packageName>
</configuration>
</execution>
<execution>
<id>xjc-schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the east directory for sources here. -->
<sources>
<source>src/main/xsds/east</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.east</packageName>
<!--
Don't clear the output directory before generating the sources.
Clearing the output directory removes the se.west schema from above.
-->
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>

Resources