Перед выполнением задач по созданию классов Java из XSD я столкнулся с проблемой использования JAXB2.XSD для Java с использованием JAXB с многоуровневым сбоем импорта
, пожалуйста, дайте мне знать, если JAXB справится с этим.
Сценарий:
1) Проект A имеет a.xsd
и b.xsd
с другим именем пространств b.xsd
использует a.xsd
с импорта имя пространства тега.
2) Проект B имеет c.xsd
и использует b.xsd
путем импорта b.xsd
.
Каталог используется c.xsd
, чтобы найти b.xsd
в Maven JAR, который добавлен в качестве зависимости.
ВОПРОС:
Проект А строит хорошо, но Project B бросает ошибку, поскольку он не может найти a.xsd
, который внутренне используемый b.xsd.
ОШИБКА
[ОШИБКА] Ошибка при анализе схемы (ы) .Location [http://www.example.com/test2/test2.xsd {15,39}]. org.xml.sax.SAXParseException; systemId: http://www.example.com/test2/test2.xsd; lineNumber: 15; columnNumber: 39; src-resolve: Не удается разрешить имя «addme: address» для компонента (n) «объявление элемента». at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:203) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error (ErrorHandlerWrapper.java: 134)
Проект A
a.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/address" xmlns="http://www.example.com/address"
elementFormDefault="qualified">
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="street" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
b.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/test2"
xmlns="http://www.example.com/test2"
xmlns:addme="http://www.example.com/address"
elementFormDefault="qualified">
<xs:import namespace="http://www.example.com/address" schemaLocation="http://www.example.com/address/address.xsd"/>
<xs:element name="test2">
<xs:complexType>
<xs:sequence>
<xs:element ref="addme:address" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Проект B
c.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/customer"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/customer"
xmlns:test="http://www.example.com/test2" elementFormDefault="qualified">
<xs:import namespace="http://www.example.com/test2"
schemaLocation="http://www.example.com/test2/test2.xsd" />
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
<xs:element ref="test:test2" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
файл каталога для проекта Б
REWRITE_SYSTEM "http://www.example.com/test2" "maven: com.test.projectA: projectA: jar ::!"
Проект А ПОМ фрагмент
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
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">
<properties>
<xsd.build.dir>${basedir}/src/main/resources</xsd.build.dir>
<generated.source.location>${basedir}/target/generated-sources/src</generated.source.location>
</properties>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generateDirectory>${generated.source.location}</generateDirectory>
<schemaDirectory>${xsd.build.dir}</schemaDirectory>
<episode>true</episode>
<addIfExistsToEpisodeSchemaBindings>true</addIfExistsToEpisodeSchemaBindings>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
<execution>
<id>attach-sources</id>
<phase>DISABLE_FORKED_LIFECYCLE_MSOURCES-13</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
**PROJECT B POM**
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" .>
<properties>
<xsd.build.dir>${basedir}/src/main/resources</xsd.build.dir>
<generated.source.location>${basedir}/target/generated-sources/src</generated.source.location>
</properties>
<dependencies>
<dependency>
<groupId>com.test.projectA</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generateDirectory>${generated.source.location}</generateDirectory>
<schemaDirectory>${xsd.build.dir}</schemaDirectory>
<catalog>src/main/resources/catalog.cat</catalog>
<useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
<execution>
<id>attach-sources</id>
<phase>DISABLE_FORKED_LIFECYCLE_MSOURCES-13</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Я не могу видеть, запись каталога для 'HTTP: // www.example.com/address'. Вероятно, он пытается загрузить его из местоположения, указанного в _b.xsd_, который является 'http: // www.example.com/address/address.xsd'. – teppic
спасибо @teppic. на самом деле я пробовал это раньше, не повезло, я думал то же самое. в основном, когда я создаю projecA, у которого есть a и b xsd, который строит отлично, проблема arriases в проекте, который имеет c xsd -> ссылки b xsd -> ссылки xsd. a и b предоставляются в качестве зависимостей, и может быть, он не может получить «а» от уровня «c», когда он разбирается, но не уверен, есть ли какой-либо конкретный способ сообщить системе или в каталоге ... – Dave