【问题标题】:JAXB classes generation from XSD schema results in a strange package structure从 XSD 模式生成 JAXB 类会导致奇怪的包结构
【发布时间】:2018-10-04 19:48:23
【问题描述】:

使用以下插件:

<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>

我从位于/src/main/resources 中的XSD 架构(比如说entity.xsd)生成类,具有命名空间定义的根元素在下面的示例中:

<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中生成的结构很奇怪:

  • target/generated-sources/jaxb
    • https
      • www_mywebpage
        • ObjectFactory.java
        • Entity.java
        • EntityDetailsRequest.java
        • EntityDetailsResponse.java

我期待的是这样的:

  • target/generated-sources/jaxb
    • com.mywebpage
      • ObjectFactory.java
      • Entity.java
      • EntityDetailsRequest.java
      • EntityDetailsResponse.java

我做错了什么?

【问题讨论】:

  • 你为什么期待com.mywebpage?你没有在任何地方指定。也许如果你明确指定&lt;packageName&gt; 你会得到你想要的。我的意思是,这是插件文档站点上的第一个 example。
  • @Andreas:我按照以下教程进行操作:howtodoinjava.com/spring-boot/…。插件应该根据命名空间生成包。

标签: java maven soap jaxb maven-jaxb2-plugin


【解决方案1】:

我在 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"

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    • 2014-02-03
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多