具有include的JAXB情节编译不起作用 [英] JAXB episode compilation with include does not work

查看:230
本文介绍了具有include的JAXB情节编译不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个架构A,B.我在B中重用了一些A元素.

I have 2 schemas A, B. I'm reusing some A elements in B.

我不使用名称空间.

我正在使用

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>

我已经在模式B中定义了模式A的包含项:

I have have defined an inclusion of schema A in schema B as:

<xs:include schemaLocation="classpath:my.schema.A.xsd"/>

,目录为

REWRITE_SYSTEM "classpath:my.schema.A.xsd" "maven:my.schema:schema-a!/A.xsd"

jaxb配置如下:

<configuration>
    <generatePackage>my.schema.b</generatePackage>
    <schemaIncludes>
        <includes>B.xsd</includes>
    </schemaIncludes>
    <episodes>
        <episode>
            <groupId>my.schema</groupId>
            <artifactId>schema-a</artifactId>
        </episode>
    </episodes>
    <catalog>src/main/catalog/catalog.cat</catalog>
</configuration>

问题是,无论何时指定情节依存关系,架构都不会生成任何类,即使它包含一些我想为其生成类的B元素.

The issue is that whenever I specify the episode dependency the schema does not generate any classes even though it contains some B elements I want to generate the classes for.

[INFO] Parsing input schema(s)...
[INFO] Compiling input schema(s)...
[INFO] Cleaning package directories.
[INFO] Finished execution.

当我删除该情节时,它可以很好地运行,并且还为模式A生成了类-我确实想避免.

When I remove the episode it works well and generates classes for schema A as well - which I indeed want to avoid.

您有什么建议吗?

样本发布于 Jaxb情节汇编

推荐答案

好的,我已经检查了您的示例.问题在于您不使用名称空间.

Ok, I've checked your example. The problem is that you don't use namespaces.

检查您的META-INF/sub-jaxb.episode文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
  <jaxb:bindings scd="x-schema::">
    <jaxb:schemaBindings map="false">
      <jaxb:package name="schema.episode.a"/>
    </jaxb:schemaBindings>
    <jaxb:bindings scd="person">
      <jaxb:class ref="schema.episode.a.Person"/>
    </jaxb:bindings>
  </jaxb:bindings>
</jaxb:bindings>

您看到此<jaxb:bindings scd="x-schema::">然后是<jaxb:schemaBindings map="false">.这基本上告诉XJC不要在空名称空间中映射任何内容".由于您的第二个架构(b.xsd)也未使用名称空间,因此当您使用a.xsd的情节文件(上面的绑定)时,也会抑制b.xsd的代码生成.

You see this <jaxb:bindings scd="x-schema::"> and then <jaxb:schemaBindings map="false">. This basically tells XJC "don't map anything in the empty namespace". Since your second schema (b.xsd) also does not use namespaces, when you use a.xsd's episode file (binding above), you suppress generation of code for b.xsd as well.

总而言之,当使用情节/单独的模式编译时,不能将具有一个名称空间的模式放入不同的情节中.这正是include的问题.

To sum it up, when using episodes/separate schema compilation you can't put schemas with one namespace into different episodes. This is exactly the issue with include.

这不是maven-jaxb2-plugin中的错误.我也不会称它为XJC中的错误.这就是情节在默认情况下的工作方式.

This is not a bug in the maven-jaxb2-plugin. I would not also call it a bug in XJC. It's just how episodes work by default.

此处中查看我的拉取请求,它演示了情节性的编译,相应地处理名称空间.

See my pull request here, it demonstrates episodic compilation, when namespaces are handled accordingly.

这篇关于具有include的JAXB情节编译不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆