When I needed convert XSD to java, I always was using JAXB. To automate XSD updates on java project maven
comes in help with jaxb2-maven-plugin
. Standard configuration in pom.xml
for this conversation looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<configuration>
<clearOutputDir>false</clearOutputDir>
<extension>true</extension>
<arguments>
<argument>-Xfluent-api</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>generate-schema</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>xsd/xsd_location</source>
</sources>
<sourceType>xmlschema</sourceType>
<xjbSources>
<xjbSource>xsd/LocalDateTimeBinding.xjb</xjbSource>
</xjbSources>
<packageName>com.example.schema</packageName>
</configuration>
</execution>
</plugin>
Where under xsd/xsd_location
I put my XSD files and xsd/LocalDateTimeBinding.xjb
contains LocalDateTime adapter for JAVA 8+ to avoid joda.time. Sources was generated to java target
folder under package name com.example.schema
. Everything was working great with simple XSD. This time i have complex one, so don't know what to do. The issue is due multiple namespaces containing same types. XSD example looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema xmlns="http://mydaomain.com/BusinessObjects/Common/AdditionalInformationDataListType/V2" targetNamespace="http://example.com/BusinessObjects/Common/AdditionalInformationDataListType/V2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://example.com/BusinessObjects/Common/AdditionalInformationDataType/V1" xmlns:ns1="http://example.com/BusinessObjects/Common/AdditionalInformationDataType/V2">
<xsd:import namespace="http://example.com/BusinessObjects/Common/AdditionalInformationDataType/V1" schemaLocation="../../../../BusinessObjects/Common/AdditionalInformationDataType/V1/AdditionalInformationDataType.xsd"/>
<xsd:import namespace="http://example.com/BusinessObjects/Common/AdditionalInformationDataType/V2" schemaLocation="../../../../BusinessObjects/Common/AdditionalInformationDataType/V2/AdditionalInformationDataType.xsd"/>
<xsd:complexType name="AdditionalInformationDataListType">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="additionalInformationDataV1" type="ns0:AdditionalInformationDataType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="additionalInformationDataV2" type="ns1:AdditionalInformationDataType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Issue is that
../../../../BusinessObjects/Common/AdditionalInformationDataType/V1/AdditionalInformationDataType.xsd
and
../../../../BusinessObjects/Common/AdditionalInformationDataType/V2/AdditionalInformationDataType.xsd
are in different folders, different version XSD types, under different namespace, but both have the same type name.
My current configuration tries to put them on the same package and I get error what file already exists. I can't change XSD (and I don't want to, because it contains over 100 files).
I was looking for some way to put different namespace sources under different packages but with no luck so far.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…