带有 annox 自定义的 JAXB 单独剧集失败:SAXParseException2 [英] JAXB separate episodes with annox customizations fails : SAXParseException2

查看:16
本文介绍了带有 annox 自定义的 JAXB 单独剧集失败:SAXParseException2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个 Maven 模块.

I have 2 maven modules.

  • 第一个只包含用于生成基本 POJO 类的 xsd 架构.
  • Second on 包含一个 xsd 模式,该模式使用目录文件导入第一个模式并生成新的 POJO 类.两代都有效.

现在,我使用 annox(Swagger 注释)向两个 xsd 文件添加注释.第一个模块编译成功,但第二个模块编译失败并出现异常:

Now, I add annotations to both xsd files with annox (Swagger annotations). First module compilation succeeded but seconds module compilation fails with and exceptions :

[ERROR] Error while generating code.Location : com.sun.istack.SAXParseException2; systemId: jar:file:/C:/commons-0.0.1-SNAPSHOT.jar!/Commons.xsd; lineNumber: 15; columnNumber: 36; compiler was unable to honor annox:annotate schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.

第一个模块

  • 'Commons.xsd':

  • 'Commons.xsd' :

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns="http://www.test.com/commons" targetNamespace="http://www.test.com/commons" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:annox="http://annox.dev.java.net" xmlns:swagger="http://annox.dev.java.net/com.wordnik.swagger.annotations" xmlns:xs="http://www.w3.org/2001/XMLSchema" jaxb:extensionBindingPrefixes="annox" jaxb:version="2.1">
  <xs:complexType name="BaseType">
    <xs:annotation>
      <xs:appinfo>
        <annox:annotate target="class">
          <swagger:ApiModel value="BaseType" description="Description" />
        </annox:annotate>
      </xs:appinfo>
    </xs:annotation>
      <xs:sequence>
        <xs:element name="field1" type="xs:integer"/>
      </xs:sequence>
  </xs:complexType>
</xs:schema>

  • 'pom.xml':

  • 'pom.xml' :

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>test</groupId>
        <artifactId>commons</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <dependencies>
            <dependency>
                <groupId>com.wordnik</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>1.3.2</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.8.3</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <args>
                                    <arg>-Xannotate</arg>
                                </args>
                                <plugins>
                                    <plugin>
                                        <groupId>org.jvnet.jaxb2_commons</groupId>
                                        <artifactId>jaxb2-basics</artifactId>
                                        <version>0.6.5</version>
                                    </plugin>
                                    <plugin>
                                        <groupId>org.jvnet.jaxb2_commons</groupId>
                                        <artifactId>jaxb2-basics-annotate</artifactId>
                                        <version>0.6.5</version>
                                    </plugin>
                                </plugins>
                            </configuration>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>com.wordnik</groupId>
                            <artifactId>swagger-annotations</artifactId>
                            <version>1.3.2</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </project>
    

  • 第二模块

    • '扩展名.xsd':

    • 'Extension.xsd' :

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns="http://www.test.com/extension" targetNamespace="http://www.test.com/extension" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:annox="http://annox.dev.java.net" xmlns:swagger="http://annox.dev.java.net/com.wordnik.swagger.annotations" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.test.com/commons" elementFormDefault="unqualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="annox" jaxb:version="2.1">
        <xs:import namespace="http://www.test.com/commons" schemaLocation="Commons.xsd" />
        <xs:complexType name="Extension">
            <xs:annotation>
                <xs:appinfo>
                    <annox:annotate target="class">
                        <swagger:ApiModel value="Extension" description="Description" />
                    </annox:annotate>
                </xs:appinfo>
            </xs:annotation>
            <xs:complexContent>
                <xs:extension base="c:BaseType">
                    <xs:sequence>
                        <xs:element name="field2" type="xs:integer" />
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:schema>
    

  • 'pom.xml':

  • 'pom.xml' :

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>test</groupId>
        <artifactId>extension</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <dependencies>
            <dependency>
                <groupId>test</groupId>
                <artifactId>commons</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.8.3</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <args>
                                    <arg>-Xannotate</arg>
                                </args>
                                <episodes>
                                    <episode>
                                        <groupId>test</groupId>
                                        <artifactId>commons</artifactId>
                                    </episode>
                                </episodes>
                                <catalog>src/main/resources/catalog.xml</catalog>
                                <plugins>
                                    <plugin>
                                        <groupId>org.jvnet.jaxb2_commons</groupId>
                                        <artifactId>jaxb2-basics</artifactId>
                                        <version>0.6.5</version>
                                    </plugin>
                                    <plugin>
                                        <groupId>org.jvnet.jaxb2_commons</groupId>
                                        <artifactId>jaxb2-basics-annotate</artifactId>
                                        <version>0.6.5</version>
                                    </plugin>
                                </plugins>
                            </configuration>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>com.wordnik</groupId>
                            <artifactId>swagger-annotations</artifactId>
                            <version>1.3.2</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </project>
    

  • 'catalog.xml' !

  • 'catalog.xml' !

    <?xml version="1.0" encoding="UTF-8"?>
    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
        <systemSuffix systemIdSuffix="Commons.xsd" uri="maven:test:commons!/Commons.xsd" />
    </catalog> 
    

  • 我试图解决这个错误已经好几天了,但没有成功.

    It's been days I'm trying to solve, without success, this error.

    推荐答案

    使用 annox 和 episodes 时存在错误.

    There is a bug using annox and episodes.

    我已经通过外部绑定(xjb 文件)解决了同样的问题.通过这种方式,架构也很干净.

    I've solved the same issue through external binding (xjb file). In this way the schema is also clean.

    例如

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <jaxb:bindings
      xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:annox="http://annox.dev.java.net"
      xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
      jaxb:extensionBindingPrefixes="xjc annox"
      version="2.1">
    
      <jaxb:globalBindings>
        <jaxb:serializable uid="12345"/> 
      </jaxb:globalBindings>
    
    
      <jaxb:bindings schemaLocation="domain1.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='SomeRootType']">
          <annox:annotate>
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SomeRootType"/>
          </annox:annotate>
        </jaxb:bindings>
      </jaxb:bindings>
    
    </jaxb:bindings>
    

    这是maven插件配置

    this is the maven plugin configuration

    <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.1</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <args>
                    <arg>-Xannotate</arg>
                    <arg>-Xnamespace-prefix</arg>
                    <arg>-nv</arg>
                </args>
                <extension>true</extension>
                <forceRegenerate>true</forceRegenerate>
                <bindingDirectory>${basedir}/src/main/resources/schema/xjb</bindingDirectory>
                <bindingIncludes>
                    <include>*.xjb</include>
                </bindingIncludes>
                <schemas>
                    <schema>
                        <fileset>
                            <directory>${basedir}/src/main/resources/schema/project/b</directory>
                            <includes>
                                <include>*.xsd</include>
                            </includes>
                        </fileset>
                    </schema>
                    <schema>
                        <dependencyResource>
                            <groupId>com.project.a</groupId>
                            <artifactId>artifact.a</artifactId>
                            <resource>schema/a.xsd</resource>
                        </dependencyResource>
                    </schema>
                </schemas>
                <episodes>
                    <episode>
                        <groupId>com.project.a</groupId>
                        <artifactId>artifact.a</artifactId>
                    </episode>
                </episodes>
                <debug>true</debug>
                <verbose>true</verbose>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.2</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics-annotate</artifactId>
                        <version>0.6.2</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>
    

    这篇关于带有 annox 自定义的 JAXB 单独剧集失败:SAXParseException2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆