簡體   English   中英

jaxb2簡化插件綁定問題

[英]jaxb2 simplify plugin binding issue

我試圖通過XJC 2.2.4使用JAXB2簡化插件。

D:\>xjc -d . -extension -p org.my.space sample.xsd parsing a schema... [ERROR] Unsupported binding namespace
"http://jaxb2-commons.dev.java.net/basic/simplify". Perhaps you meant
"http://jaxb.dev.java.net/plugin/code-injector"?   line 7 of file:/D:/sample.xsd
Failed to parse a schema.

sample.xsd具有聲明的simple

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
    xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
    jaxb:extensionBindingPrefixes="simplify"
    xmlns="http://www.example.org/sampleXML" targetNamespace="http://www.example.org/sampleXML"
    elementFormDefault="qualified">

有什么想法嗎?

編輯:我嘗試了其他方法與綁定文件xjb和仍然相同的錯誤。 這是否意味着我的XJC版本(2.2)不支持JAXB2簡化?

xjc -d -擴展名-b bindings.xjb sample.xsd

<bindings version="2.1"
      xmlns="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
      extensionBindingPrefixes="simplify">

    <bindings schemaLocation="sample.xsd" node="/xs:schema">
        <bindings
            node="/xs:schema/xs:complexType[@name='dlist']/xs:choice/xs:element[1]">
            <simplify:as-element-property />
        </bindings>
    </bindings>

</bindings>

我切換到了maven jaxb2 plugin並且經過更多的努力后,它仍然可以正常工作。 對於將來遇到麻煩的人。 此設置在JDK 1.6中正常工作(對於仍無法遷移的用戶)。

的pom.xml

<build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <!--  plugin to compile schemas to JAXB classes -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb21-plugin</artifactId>
                <version>0.13.1</version>
                <executions>
                    <execution>
                        <id>generate-JAXB</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <forceRegenerate>true</forceRegenerate>
                            <schemaDirectory>src/main/resources</schemaDirectory>
                            <schemaIncludes>
                                <include>sample.xsd</include>
                            </schemaIncludes>
                            <cleanPackageDirectories>true</cleanPackageDirectories>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xsimplify</arg>
                    </args>
                    <plugins>
                        <plugin>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-basics</artifactId>
                            <version>0.11.0</version>
                        </plugin>
                    </plugins>
                </configuration>
            </plugin>
        </plugins>
    </build>

我沒有使用binding.xjb因為我已經將simplify直接包括在架構中(因為我可以訪問)。

sample.xsd

<xs:complexType name="doclist">
    <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:annotation>
                <xs:appinfo>
                    <simplify:as-element-property />
                </xs:appinfo>
            </xs:annotation>
            <xs:element name="document1" type="type1" />
            <xs:element name="document2" type="type2" />
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="heading" type="xs:string" />
</xs:complexType>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM