[英]Maven Fails to Generate JAXB Classes Using Nested Schemas
我試圖讓Maven使用嵌套的xml模式生成JAXB綁定:模式A導入模式B。模式B導入模式C。
如果架構A中的對象引用架構B中的對象,而這些對象不依賴於架構C對象,則一切都可以構建。 如果模式B中的對象引用模式C中的對象,則它將中斷。 也就是說,深入一層工作。 深入兩步不會。
一旦在架構A中添加了一個引用架構B中的對象的對象,而該對象又又引用了架構C中的對象,我得到一個org.xml.sax.SAXParseException:rc-resolve:無法解析名稱'schemaB: objectInSchemaB”到(n)“類型定義”組件。
如果省略頂層模式A,也可以成功構建,而僅從編譯模式B導入模式C開始。因此,問題再次出現了嵌套導入的問題。
我被卡住了!
JAXB版本:
檢測到JAXB API版本[2.2]。 pluginArtifacts:[org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:maven-plugin:0.9.0 :, org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-core:jar:0.9.0:compile, com.sun.org.apache.xml.internal:resolver:jar:20050927:compile,org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile,junit:junit:jar:4.8.1:編譯,org.codehaus.plexus:plexus-utils:jar:1.5.15:compile,org.jvnet.jaxb2.maven2:maven-jaxb22-plugin:jar:0.9.0:compile,javax.xml.bind:jaxb- api:jar:2.2.7:compile,com.sun.xml.bind:jaxb-impl:jar:2.2.7:compile,com.sun.xml.bind:jaxb-core:jar:2.2.7:compile, com.sun.istack:istack-commons-runtime:jar:2.16:compile,com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile,javax.xml.bind:jsr173_api:jar:1.0:compile, com.sun.xml.bind:jaxb-xjc:jar:2.2.7:compile,org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2:compile] specVersion:2.2
以下是我的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<schemaInclude>**/*.xsd</schemaInclude>
</schemaIncludes>
<strict>true</strict>
<verbose>true</verbose>
<extension>true</extension>
<removeOldOutput>true</removeOldOutput>
<specVersion>2.2</specVersion>
<episode>true</episode>
<episodeFile>${project.build.directory}/generated-sources/xjc/META-INF/jaxb-example.episode</episodeFile>
</configuration>
<id>jaxb-generate-example</id>
</execution>
</executions>
<configuration>
<catalog>src/main/resources/jaxb/catalog.xml</catalog>
<catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
<forceRegenerate>true</forceRegenerate>
<generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
<verbose>true</verbose>
<args>
<arg>-enableIntrospection</arg>
</args>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
下面的“模式A”。 如果我注釋掉baseSystemConfig對象,則將編譯架構。
<?xml version="1.0"?>
<xsd:schema version="1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://ws.zwake.com/schema/zwakkiCentralCommon"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:zwakkiBase="http://ws.zwake.com/schema/zwakeBase"
jaxb:version="2.1">
<!-- Schema B import -->
<xsd:import namespace="http://ws.zwake.com/schema/zwakeBase" schemaLocation="../ZwakeBase/zwakeBase.xsd"/>
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings typesafeEnumMemberName="generateName"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="RetrieveBaseSystemConfigsRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="credentials" type="zwakkiBase:Credentials"/>
<xsd:element name="restrictToBaseSystemIds" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RetrieveBaseSystemConfigsResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="baseSystemConfig" type="zwakkiBase:ZwakeConfig" maxOccurs="unbounded"/>
<xsd:element name="responseStatus" type="zwakkiBase:SystemError" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
我找到了原因:在嵌套模式中,我指向的是元素而不是complexType(編譯錯誤表示為“ a type”)。 這導致了編譯失敗。 我需要使用ref =而不是type =,或更改架構B的定義。
因此,這種情況的案例一開始就太明顯了。 感謝Xstian確認它應該可以正常工作。 這使我找到了正確的道路。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.