java - JAXB schemagen 不引用剧集文件中的类

标签 java jaxb jaxb2 jaxb2-maven-plugin schemagen

我实际上使用的是架构优先方法,但是我遇到了“不祥”的障碍 JAXB Map problem !并通过为此切换到代码优先方法来解决它。现在我想在其他模块中重用这种类型,并通过从生成的模式创建剧集文件来继续我的模式优先方法。不幸的是,生成的剧集文件是空的。这是我尝试过的:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>schemagen</id>
            <goals>
                <goal>schemagen</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <configuration>
        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
        <generateEpisode>true</generateEpisode>
        <transformSchemas>
            <transformSchema>
                <uri>http://some/schema/types</uri>
                <toPrefix>core</toPrefix>
                <toFile>core-types.xsd</toFile>
            </transformSchema>
        </transformSchemas>
    </configuration>
</plugin>

这为我生成了以下架构:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="http://some/schema/types" targetNamespace="http://some/schema/types" version="1.0">
  <xs:element name="Map" type="core:MapType"/>

  <xs:complexType name="MapType">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="entries" nillable="true" type="core:EntryType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="EntryType">
    <xs:sequence>
      <xs:element name="key" type="xs:anyType"/>
      <xs:element name="value" type="xs:anyType"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

以及包含此内容的剧集文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:bindings version="2.1" xmlns:ns1="http://java.sun.com/xml/ns/jaxb"/>

我尝试使用 schemagen standalone(版本 2.2.11)得到类似的结果。 https://jaxb.java.net/2.2.4/docs/schemagen.html 处的文档和 http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/schemagen-mojo.html接缝表明这应该是它,但我无法弄清楚我做错了什么。

最佳答案

我解决了问题...按照上面的操作:

    <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <id>schemagen</id>
                            <goals>
                                <goal>schemagen</goal>
                            </goals>
                            **<phase>generate-sources</phase>**
                        </execution>
                    </executions>

                    <configuration>             

                    **<xsdPathWithinArtifact>generated/xsds</xsdPathWithinArtifact>**

</configuration>


    </plugin>

关于java - JAXB schemagen 不引用剧集文件中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36714142/

相关文章:

xml-parsing - 使用 JAXB 对 XML 进行部分解码以跳过一些 xmlElement

spring - Jaxb2Marshaller 与 Spring 集成

java - 与远程主机的 TCP 套接字连接失败 (EINVAL)

java - 从 XML 文件读取内容时如何保留 "Character Reference Codes"(<)

java - 单击时图像不居中

java - 从 JAX-WS 服务获取原始负载

java - 是否可以使用 JAXB 根​​据某些属性值获取 XML 元素?

java - JAXB boolean 值 TRUE/FALSE 大写返回 null

java - 替换 JavaFX GridPane 中(行,列)处的节点

java - 是否可以从方法返回