什么是.episode文件..?

问题描述 投票:30回答:4

什么是JAXB中的.episode文件..?它是由JAXB生成的还是我们操作的配置文件,以避免JAXB重新生成相同的类?

java web-services jaxb web
4个回答
29
投票

注意:我是EclipseLink JAXB (MOXy)的领导者和JAXB 2 (JSR-222)专家组的成员。

.episode文件由XJC(XML Schema to Java)编译器生成。它是一种模式绑定,它将模式类型与现有类相关联。当您有一个由其他模式导入的XML模式时,它很有用,因为它会阻止模型重新生成。以下是一个例子:

Product.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/Product" 
    xmlns:tns="http://www.example.org/Product" 
    elementFormDefault="qualified">
    <element name="product">
        <complexType>
            <sequence>
                <element name="id" type="string"/>
                <element name="name" type="string"/>
            </sequence>
        </complexType>
    </element>
</schema>

由于多个XML模式导入Product.xsd,我们可以利用episode文件,以便只生成一次与Product.xsd相对应的类。

xjc -d out -episode product.episode Product.xsd

ProductPurchaseRequest.xsd

下面是导入Product.xsd的XML模式的示例:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/ProductPurchaseRequest" 
    xmlns:tns="http://www.example.org/ProductPurchaseRequest"
    xmlns:prod="http://www.example.org/Product" 
    elementFormDefault="qualified">
    <import namespace="http://www.example.org/Product" schemaLocation="Product.xsd"/>
    <element name="purchase-request">
        <complexType>
            <sequence>
                <element ref="prod:product" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>
</schema>

当我们从这个XML模式生成类时,我们将引用我们从Product.xsd生成Java类时创建的剧集文件。

xjc -d out ProductPurchaseRequest.xsd -extension -b product.episode

ProductQuoteRequest.xsd

下面是导入Product.xsd的XML模式的另一个示例:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/ProductQuoteRequest" 
    xmlns:tns="http://www.example.org/ProductQuoteRequest" 
    xmlns:prod="http://www.example.org/Product" 
    elementFormDefault="qualified">
    <import namespace="http://www.example.org/Product" schemaLocation="Product.xsd"/>
    <element name="quote">
        <complexType>
            <sequence>
                <element ref="prod:product"/>
            </sequence>
        </complexType>
    </element>
</schema>

再次,当我们从这个XML模式生成类时,我们将引用我们从Product.xsd生成Java类时创建的剧集文件。

xjc -d out ProductQuoteRequest.xsd -extension -b product.episode

欲获得更多信息


7
投票

我会添加一些琐事。

  • 实际上,.episode文件只是普通的绑定文件(这就是为什么它们与xjc -b一起工作)。
  • 它们可以使用特殊的内置插件生成(这就是-episode所做的)。
  • 如果放置在META-INF/sun-jaxb.episode路径下的JAR中,您可以执行xjc b.xsd a.jar - XJC将扫描JAR以查找剧集文件,然后自动使用作为绑定文件。
  • 所有这些美女都可以和Maven(maven-jaxb2-plugin)一起使用。但是,对于更高版本,即使没有剧集,您也可以使用JAR工件中的绑定文件。

0
投票

显然,他们是为了modular schema creation

这意味着文件本身既可以用作配置器,也可以用作下游处理的数据层的生成视图。需要更多背景来确定这里提到的内容。


0
投票

只是答案的一个插件,我想提供一个输入,说明如何避免在使用maven-jaxb2-plugin时生成.episode文件

         `<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.12.3</version>
            <executions>
                <execution>
                    <id>schema-conversion</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaDirectory>src/main/schema/myschema</schemaDirectory>
                        <bindingDirectory>src/main/schema/myschema</bindingDirectory>
                        <bindingIncludes>
                            <include>binding_info.xjb</include>
                        </bindingIncludes>
                        <generateDirectory>src/main/java/</generateDirectory>
                        <episode>false</episode>
                    </configuration>
                </execution>
            </executions>
        </plugin>`

<episode>false</episode>将使它消失。

© www.soinside.com 2019 - 2024. All rights reserved.