the approach is to generate java classes by xsd using jaxb2-maven-plugin.
The pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>${project.groupId}.model</packageName>
<extension>true</extension>
<arguments>-b ${resource.dir}/jaxbbindings.xsd -Xannotate</arguments>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<schemaFiles>1.0.xsd</schemaFiles>
<clearOutputDir>true</clearOutputDir>
</configuration>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</plugin>
And the xsd 1.0:
<xs:schema
targetNamespace="http://example.com/1.0"
xmlns:gs="http://example.com/1.0"
xmlns:cmn="http://example.com/another"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="another.xsd"
namespace="http://example.com/another" />
....
</xs:schema>
As you can seen with the import tag I intend to import another schema.
another.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://example.com/another"
xmlns:vt="http://example.com/another">
...
</xs:schema>
So, if maven executes XJC to generate the java classes by XSD, the package-info is also generated:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://example.com/another")
package de.fraunhofer.fokus.testing.fokusmbt.specexplorer.model;
As you can seen above the namespace is http://example.com/another. But this is wrong. The namespace should be http://example.com/1.0.
The another stuff works fine (generating java classes and so on).
What do I wrong?
you generate 2 set of classes 1# http://example.com/another 2# http://example.com/1.0. For each set of classes will be generated package-info.java
, but you override a generation folder in "${project.groupId}.model"
so you have one package-info.java
that define only one namespace.
You should remove <packageName>${project.groupId}.model</packageName>
and all works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With