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>
Related
I'm trying to create a bind file to change the base type of a property:
XSD
My bind file:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"
version="2.1">
<bindings schemaLocation="*">
<bindings node="//xsd:element[#name='EFilingPriorDocumentNumber']">
<baseType name="java.lang.String"/>
</bindings>
</bindings>
</bindings>
But XJC always give me the error:
[ERROR] XPath evaluation of "//xsd:element[#name='EFilingPriorDocumentNumber']" results in empty target node
Someone knows how to fix it?
I'm trying to change the package name space for some namespaces because they have objects that collide.
Here is the wsdl:
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/"
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
</wsdl:definitions>
Here are the bindings:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0"
wsdlLocation="https://localhost/DS/Search.svc?wsdl">
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://localhost.datacontract.org/2004/07/Search.Models.SearchAPI']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice.model"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
When I run wsimport with the -b option I get this error
[ERROR] XPath evaluation of "//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']" results in empty target node
line 7 of file:service-bindings.xml
I get the error for both bindings..
Am I missing something with the definition of the bindings?
I found a way round this issue by using the global binding. The binding will create the serivce ObjectFactory but not the model pojos.
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
Hi I'm trying to create an external bindings XML for xjc but I'm getting 2 errors:
[ERROR] A class/interface with the same name "x.x.DaysOfWeek" is already in use. Use a class customization to resolve this conflict.
[ERROR] (Relevant to above error) another "DaysOfWeek" is generated from here.
Am I missing something major? I need a second pair of eyes. Thanks
<!-- data.xsd -->
<xs:complexType name="DaysOfWeek">
<xs:sequence>
<xs:element ref="DaysOfWeek"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DaysOfWeek">
<xs:complexType mixed="true">
<xs:attribute name="Type" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
and I have bindings.xml right now
<jaxb:bindings version="1.0" 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"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings schemaLocation="data.xsd">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.kml.v_2_2_0"/>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:factoryMethod name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
You have a collision on generated classes. Try adding:
<jaxb:bindings node="xs:element[#name='DaysOfWeek']//xs:complexType">
<jaxb:class name="ComplexDaysOfWeekType"/>
</jaxb:bindings>
(Maybe without //xs:complexType, not quite sure.)
The issue has been solved using
<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:class name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
I have a WSDL file weatherservice.wsdl and I am trying to generate binding for this WSDL using xjc. How do I do this using xjc?
I did not find any command line args to do it from xjc. xjc -p com -wsdl weatherservice.wsdl
Generally we create a bindings file with .xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.
Here is an example:
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
version="2.1">
<jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true">
<xjc:serializable uid="1" />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="abcd.xsd">
<jaxb:bindings node="//xs:element[#name='Event']/xs:simpleType">
<jaxb:typesafeEnumClass name="EventEnumType" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Try using this simple binding. Save it next to the WSDL and tell XJC to use that.
<bindings version="2.0"
xmlns="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"
>
<globalBindings>
<xjc:simple/>
</globalBindings>
</bindings>
You could do it through the Maven plugin, which simplifies a bit, and complicates a bit.
This will take a few XSDs and apply the XJBs to generate the Java classes:
<!-- Docs:
Maven plugin: http://cxf.apache.org/cxf-xjc-plugin.html
XJC: https://javaee.github.io/jaxb-v2/doc/user-guide/ch04.html
https://tech.boldare.com/make-jaxb-great-again/
-->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>${version.cxf-xjc}</version>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/main/java</sourceRoot>
<xsdOptions>
<xsdOption>
<extension>true</extension>
<xsd>${xsdsBaseDir}/someService/some-soap-service.xsd</xsd>
<!-- Args to XJC execution -->
<extensionArgs>
<extensionArg>-XautoNameResolution</extensionArg>
<extensionArg>-encoding</extensionArg><extensionArg>UTF-8</extensionArg>
</extensionArgs>
</xsdOption>
<xsdOption>
<!-- another XSD... -->
</xsdOption>
</xsdOptions>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-wsdlextension:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-boolean:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-ts:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-bug671:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-bug986:${version.cxf-xjc}</extension>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-javadoc:${version.cxf-xjc}</extension>
<!--
-->
</extensions>
</configuration>
<executions>
<execution>
<id>generate-from-xsds</id><phase>generate-sources</phase><goals><goal>xsdtojava</goal></goals>
</execution>
</executions>
</plugin>
Two gotchas:
The plugin can't take defaults from the execution config - must be set in the plugin-level config.
You'll need to add the sources to the reactor, if you have some tests of the schema within the same module.
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>