【发布时间】:2016-11-03 15:57:08
【问题描述】:
我想从我的 Java 项目中调用 ISAN Restful API,所以我尝试使用 maven-jaxb2-plugin 从 xsd 文件生成 java bean。 这是xsds:
- http://www.isan.org/schema/v1.11/common/common.xsd
- http://www.isan.org/schema/v1.21/common/serial.xsd
- http://www.isan.org/schema/v1.11/common/version.xsd
- http://www.isan.org/ISAN/isan.xsd
- http://www.isan.org/schema/v1.11/common/title.xsd
- http://www.isan.org/schema/v1.11/common/externalid.xsd
- http://www.isan.org/schema/v1.11/common/participant.xsd
- http://www.isan.org/schema/v1.11/common/language.xsd
- http://www.isan.org/schema/v1.11/common/country.xsd
我下载了这些文件并将它们复制到我的 src/main/resources 文件夹中。 这是我在 pom.xml 中的插件配置:
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
</configuration>
<executions>
<execution>
<id>isan</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatePackage>org.isan</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/isan</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
现在插件告诉我某些类型被定义了多次。例如:
03/11/2016 16:42:53 UTC+1:[错误] 解析架构时出错。位置 [file:/D:/isan/isan/src/main/resources/common.xsd{ 51,37}]。 'DurationType' 已定义 2016 年 3 月 11 日 16:42:53 UTC+1:[错误] 解析架构时出错。位置 [http://www.isan.org/schema/v1.11/common/common.xsd{46,38}]。 (与上述错误有关)这里出现第一个定义
我理解这是因为每种类型都在我的本地文件和远程文件中定义。一种解决方案似乎是使用目录 (https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs),但它似乎不起作用。
我在“src/main/resources:”中添加了这个目录
PUBLIC "http://www.isan.org/schema/v1.11/common/common.xsd" "./common.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/country.xsd" "./country.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/externalid.xsd" "./externalid.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/isan.xsd" "./isan.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/language.xsd" "./language.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/participant.xsd" "./participant.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/serial.xsd" "./serial.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/title.xsd" "./title.xsd"
PUBLIC "http://www.isan.org/schema/v1.11/common/version.xsd" "./version.xsd"
REWRITE_SYSTEM "http://www.isan.org" "isan"
并修改插件配置:
<configuration>
<strict>false</strict>
<catalog>src/main/resources/catalog.cat</catalog>
<generatePackage>org.isan</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/isan</generateDirectory>
</configuration>
我仍然遇到同样的错误
【问题讨论】: