我实际上使用的是模式优先方法,但是我遇到了“不祥” 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(2.2.11版),结果相似。 https://jaxb.java.net/2.2.4/docs/schemagen.htmlhttp://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/

10-15 11:40