0

My project contains A.xsd which imports schema as follows from B.xsd which is part of another project:

<xsd:import namespace="http://com.test.schema/common/Context" schemaLocation="http://com.test.schema/common/Context/B.xsd"/>

I am trying to use the episode from the project which contains B.xsd so that classes related to B.xsd do not get re-generated when A.xsd is parsed. So I referred this and this to come up with the following configuration: Here is the pom.xml

    <dependencies>
        <dependency>
            <groupId>com.bar.foo</groupId>
            <artifactId>schema-b</artifactId>
            <version>1.2</version>
        </dependency>
    <dependencies>
    .
    .
    .
    .
    .
    <build>
        <plugins>
        <dependency>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <extension>true</extension>
                            <episodes>
                                <episode>
                                    <groupId>com.bar.foo</groupId>
                                    <artifactId>schema-b</artifactId>
                                </episode>
                            </episodes>
                            <catalog>src/main/resources/catalog.cat</catalog>
                            <schemas>
                                <schema>

                                    <fileset>
                                        <directory>${basedir}/src/main/schemas</directory>
                                        <includes>
                                            <include>A.xsd</include>
                                            <include>...</include>
                                            <include>...</include>
                                        </includes>
                                    </fileset>
                                </schema>
                            </schemas>
                            <bindingDirectory>${basedir}/src/main/schemas</bindingDirectory>
                            <bindingIncludes>
                                <include>*.xjb</include>
                            </bindingIncludes>
                            <args>
                                <arg>-Xannotate</arg>
                            </args>
                            <plugins>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>0.6.0</version>
                                </plugin>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics-annotate</artifactId>
                                    <version>0.6.0</version>
                                </plugin>
                            </plugins>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Here is the catalog file:

PUBLIC "http://com.test.schema/common/Context" "maven:com.bar.foo:schema-a:jar::1.2!"

There is some configuration in the xjb file to make sure that XmlRootElement is written into some generated classes:

<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="2.1" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net" extensionBindingPrefixes="xjc">
<jxb:globalBindings>
    <xjc:simple />
</jxb:globalBindings>   
<jxb:bindings
    schemaLocation="A.xsd">
    <jxb:bindings node="//xsd:complexType[@name='ADataType']">
        <jxb:class name="AData" />
        <annox:annotate>
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
                name="AData" />
        </annox:annotate>
    </jxb:bindings>
</jxb:bindings>

Inspite of providing the episode to the xjc execution and the location of the schema for B.xsd in the catalog file, the classes for B.xsd is getting generated.

The issue is that the maven artifact referred to by the catalog file is not being picked up. I see the following error in the maven build logs:

Malformed URL on system identifier: maven:com.bar.foo:schema-b:jar::1.2!
PUBLIC: http://com.test.schema/common/Context
maven:com.bar.foo:schema-a:jar::1.2!

Can anyone help tell me why am I hitting this malformed URL error for the artifact that contains B.xsd? Any help will be really appreciated.

4

1 回答 1

1

免责声明:我是的作者。

A首先,你可能B在这里混音。您说的是A导入B,但随后您将schema-a工件用作插曲。如果B是导入的,你应该在编译时使用schema-bas episode 来不重新生成东西。BA

但我认为这可能只是问题中的一个小错误。

这里有两个方面 - 剧集和目录。

剧集允许您跳过已经在其他地方生成的类的生成。因此,如果您schema-b在编译时使用工件,schema-a那么 XJC 不应该为schema-b. 你不需要目录,它是独立的。

有时 XJC 仍然会产生很少的剩余部分——即使你使用一个插曲。我经常得到ObjectFactory并且可能生成一些枚举或顶级元素。我相信这是 XJC 中的一个问题,在中我无能为力。
所以作为一种解决方法,我只是maven-antrun-plugin用来删除不必要的生成的东西。

如果您B生成了所有的东西,那么您应该检查schema-b工件是否真的生成了剧集文件。检查您是否META-INF/sun-jaxb.episode在 JAR 中。有关剧集文件的一些琐事,请参阅此答案

因此,如果您正确配置了正确的剧集工件,您就不应该B生成任何东西,您不需要为此创建目录。

您需要目录是为了避免http://com.test.schema/common/Context/B.xsd在编译时下载。您可以使用目录指向另一个位置。我认为您的问题是您所指http://com.test.schema/common/Contextmaven:com.bar.foo:schema-a:jar::1.2!显然不指向架构资源。

如果您有类似的导入

<xsd:import namespace="http://com.test.schema/common/Context" schemaLocation="http://com.test.schema/common/Context/B.xsd"/>

那么您可能应该将其重写如下:

PUBLIC "http://com.test.schema/common/Context" "maven:com.bar.foo:schema-b:jar::1.2!/common/Context/B.xsd"

假设schema-b工件包含您的架构在/common/Context/B.xsd. 请注意,它映射的是名称空间,而不是模式位置

您还可以使用REWRITE_SYSTEM重写架构位置。例如:

REWRITE_SYSTEM "http://com.test.schema" "maven:com.bar.foo:schema-b:jar::1.2!"

如果你有一个类似的 URL http://com.test.schema/common/Context/B.xsd,它将被重写为maven:com.bar.foo:schema-b:jar::1.2!/common/Context/B.xsd. 这将指向JAR/common/Context/B.xsd中的资源。schema-b

另一个提示 - 如果您schema-b在项目中用作依赖项,则可以省略版本。

以下是来自真实项目的目录示例:

https://github.com/highsource/ogc-schemas/blob/master/schemas/src/main/resources/ogc/catalog.cat

它包含如下重写:

REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
于 2015-10-02T06:56:09.793 回答