Java 什么是 .episode 文件..?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9756185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:13:39  来源:igfitidea点击:

What is an .episode file..?

javaweb-servicesjaxbweb

提问by quantumcrypt

what is a .episode file in JAXB..? Is it generated by the JAXB or is it a configuration file that we'd manipulate to avoid regeneration of the same classes by JAXB..?

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

采纳答案by bdoughan

Note:I'm the EclipseLink JAXB (MOXy)lead and a member of the JAXB 2 (JSR-222)expert group.

注意:我是EclipseLink JAXB (MOXy) 的负责人和JAXB 2 (JSR-222)专家组的成员。

A .episode file is generated by the XJC (XML Schema to Java) compiler. It is a schema bindings that associates schema types with existing classes. It is useful when you have one XML schema that is imported by other schemas as it prevents the model from being regenerated. Below is an example:

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

Product.xsd

产品.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>

Since multiple XML schemas import Product.xsd we can leverage episode files so that the classes corresponding to Product.xsd are only generated once.

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

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

ProductPurchaseRequest.xsd

产品采购请求.xsd

Below is an example of an XML schema that imports Product.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>

When we generate classes from this XML schema we will reference the episode file we created when we generated Java classes from Product.xsd.

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

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

ProductQuoteRequest.xsd

产品报价请求.xsd

Below is another example of an XML schema that imports Product.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>

Again when we generate classes from this XML schema we will reference the episode file we created when we generated Java classes from Product.xsd.

同样,当我们从这个 XML 模式生成类时,我们将引用我们在从 Product.xsd 生成 Java 类时创建的情节文件。

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

For More Information

想要查询更多的信息

回答by MrGomez

Apparently, they're for modular schema creation.

显然,它们用于模块化架构创建

This implies that the files themselves can be used both as a configurator and as a generative view of a data layer for downstream processing. More context would be needed to determine which is being referred to here.

这意味着文件本身既可以用作配置器,也可以用作下游处理的数据层的生成视图。需要更多上下文来确定此处所指的是哪个。

回答by lexicore

I'll add some trivia.

我会补充一些琐事。

  • Actually, .episodefiles are just normal binding files (that's why they work with xjc -b).
  • They can be generated with a special built-in plugin (that's what -episodedoes).
  • If placed in a JAR under the META-INF/sun-jaxb.episodepath, you can do xjc b.xsd a.jar- XJC will scan JARs for episode files then an use the as binding files automatically.
  • All of this beauty works fine with Maven (maven-jaxb2-plugin). However, with later version you can use binding files from JAR artifacts even without episodes.
  • 实际上,.episode文件只是普通的绑定文件(这就是它们使用 的原因xjc -b)。
  • 它们可以使用特殊的内置插件生成(就是这样-episode做的)。
  • 如果放置在META-INF/sun-jaxb.episode路径下的 JAR 中,您可以这样做xjc b.xsd a.jar- XJC 将扫描 JAR 中的剧集文件,然后自动使用作为绑定文件。
  • 所有这些美都适用于 Maven ( maven-jaxb2-plugin)。但是,在更高版本中,即使没有剧集,您也可以使用来自 JAR 工件的绑定文件。

回答by Suraj Muraleedharan

Just an addon to the answer, I would like to provide an input on how to avoid having .episode file generated while using maven-jaxb2-plugin

只是答案的一个插件,我想提供有关如何避免在使用 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>will make it disappear.

<episode>false</episode>会让它消失。