maven - jaxb-maven-plugin 的 IntelliJ bindingDirectory

标签 maven intellij-idea jaxb jaxb2-maven-plugin

我想在单独的 schema.xjb 绑定(bind)文件中为我的 schema.xsd 生成的类型添加 globalBinding。我正在使用 IntelliJ,但不确定这个问题是 maven 还是 Intellij 造成的(例如,此示例在 eclipse 中按预期运行)。我得到的错误是:

org.xml.sax.SAXParseException; systemId: file:/D:/Projects/Location/To/Project/src/main/resources/xsd/schema.xsd; lineNumber: 7; columnNumber: 10; vendor extension bindings (jaxb:extensionBindingPrefixes) are not allowed in the strict mode. Use -extension.

这是我的 pom.xml 中的构建元素:
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The name of your generated source package -->
                <packageName>com.my.model.example</packageName>
                    <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
                <!-- Well Intellij acts badly when it comes down to binding files, so there is that. -->
                <bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>
            </configuration>
        </plugin>

    </plugins>

</build>

这是我位于/src/main/resources/xsd 中的架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           id="SampleSchema"
           targetNamespace="http://sample.com/namespace"
           elementFormDefault="qualified"
           xmlns="http://sample.com/namespace"
        >

    <xs:element name="Example">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string" maxOccurs="unbounded" />
                <xs:element name="street" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

这是我的 bindingFile 位于/src/main/resources/xjb
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          version="2.0"
          xsi:schemaLocation="../xsd/schema.xsd">
    <jxb:globalBindings>
        <xjc:simple/>
    </jxb:globalBindings>
</jxb:bindings>

任何提示如何解决这个问题都会很棒!

最佳答案

好吧,伙计们,我发现了似乎是什么问题。我错过了 <extension>我的 <configuration> 中的元素pom.xml 中的元素!像这样:

<configuration>

<packageName>com.my.model.example</packageName>
<schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>

<!-- tada! -->
<extension>true</extension>
</configuration>

关于maven - jaxb-maven-plugin 的 IntelliJ bindingDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17251345/

相关文章:

spring - 无法通过 Junit 加载 applicationContext 来测试类

java - Maven maven-war-plugin 不替换 web.xml 中的值

java - 如何将此 (github) 源代码制作成库/jar?

java - 获取像 "Two classes have the same XML type name..."这样的 JAXB 异常

java - Spring security 5 迁移指南

maven - 如何从非build-gradle文件访问Kotlin DSL扩展?

java - Eclipse 不显示 git repo 中的所有包

intellij-idea - 无法将 functx 库与 intellij idea 社区版一起使用

java.lang.NoClassDefFoundError java 中的异常

java - 获取多个同名的 XML 元素 JAXB