我有这个问题
org.codehaus.mojo
JAXB2-行家-插件
我有各种XSD-s,并且在不同的xsd-s中有相同的元素/类型属于同一名称空间。
现在我想知道我可以为不同的命名空间创建包,这样我就不会有双重类吗?
这是我的pom.xml
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${mvn-jaxb2-plugin.version}</version>
<configuration>
<quiet>true</quiet>
<verbose>false</verbose>
<clearOutputDir>false</clearOutputDir>
<readOnly>true</readOnly>
<arguments>-mark-generated</arguments>
</configuration>
<executions>
<execution>
<id>teenus-meta</id>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/teenus1</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<packageName>ee.teenus</packageName>
<schemaFiles>one.xsd</schemaFiles>
</configuration>
</execution>
<execution>
<id>vaetis</id>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/teenus2</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<packageName>ee.teenus2</packageName>
<schemaFiles>two.xsd</schemaFiles>
</configuration>
</execution>
</executions>
此时package1和package2包含相同的元素。
谢谢!
答案 0 :(得分:1)
最近,我需要来自各种xsd的不同命名空间的包。找到的解决方案是使用绑定文件。也许你应该使用绑定文件......
<executions>
<execution>
<id>one</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
<schemaFiles>one.xsd</schemaFiles>
<bindingDirectory>${basedir}/src/main/resources/binding</bindingDirectory>
<bindingFiles>onebinding.xjb</bindingFiles>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
<extension>true</extension>
</configuration>
</execution>
<execution>
<id>two</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
<schemaFiles>two.xsd</schemaFiles>
<bindingDirectory>${basedir}/src/main/resources/binding</bindingDirectory>
<bindingFiles>twobinding.xjb</bindingFiles>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
<extension>true</extension>
</configuration>
</execution>
</executions>
onebinding.xjb
<jaxb:bindings jaxb:extensionBindingPrefixes="xjc" version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxb:globalBindings>
<xjc:simple/>
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="../xsd/one.xsd">
<jaxb:schemaBindings>
<jaxb:package name="my.package.one" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="http://www.example.com/xmlns/example1.xsd">
<jaxb:schemaBindings>
<jaxb:package name="my.package.one.example1" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
twobinding.xjb
<jaxb:bindings jaxb:extensionBindingPrefixes="xjc" version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxb:globalBindings>
<xjc:simple/>
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="../xsd/two.xsd">
<jaxb:schemaBindings>
<jaxb:package name="my.package.two" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="http://www.example.com/xmlns/example1.xsd">
<jaxb:schemaBindings>
<jaxb:package name="my.package.two.example1" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>