首页 > 解决方案 > 从 XSD 模式生成 JAXB 类会导致奇怪的包结构

问题描述

使用以下插件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
        <clearOutputDir>false</clearOutputDir>
    </configuration>
</plugin>

我从entity.xsd放置在 中的 XSD 模式(比方说)生成类,/src/main/resources具有命名空间定义的根元素在下面的示例中:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:webpage="https://www.mywebpage.com"
    targetNamespace="https://www.mywebpage.com"
    elementFormDefault="qualified">

    ...
</xs:schema>

mvn clean install上,生成的结构target/generated-sources/jaxb非常奇怪:

我期待的是:

我做错了什么?

标签: javamavensoapjaxbmaven-jaxb2-plugin

解决方案


我在 XSD 架构中有一个错误。maven-jaxb2-plugin不承认,https但只有http.

我变了:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:webpage="https://www.mywebpage.com"
    targetNamespace="https://www.mywebpage.com"

至:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:webpage="http://www.mywebpage.com"
    targetNamespace="http://www.mywebpage.com"

生成的结构符合我的预期并在我的问题中描述。


推荐阅读