0

我正在尝试使用 maven-jaxb2-plugin 从 .xsd 文件中生成 Java 类,并向它们添加 @XmlRootElement 注释。我一直在遵循http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html的说明

mvn clean install我收到以下错误:

[ERROR] Error while generating code.Location[...].
com.sun.istack.SAXParseException2; [...] compiler was unable to honor this annox:annotate customization. It is attached to a wrong place, or its inconsistent with other bindings.

我熟悉文章JAXB 独立剧集与 annox 自定义失败:SAXParseException2但它不能解决我的问题。

我的 pom.xml 配置:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <id>generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generatePackage>ws.model</generatePackage>
                    <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
                    <schemaIncludes>
                        <include>*.xsd</include>
                    </schemaIncludes>
                    <bindingDirectory>${project.basedir}/src/main/resources/xsd</bindingDirectory>
                    <bindingIncludes>
                        <include>*.xjb</include>
                    </bindingIncludes>
                    <extension>true</extension>
                    <strict>false</strict>
                    <args>
                        <arg>-Xannotate</arg>
                    </args>
                    <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>
                    </plugins>
                </configuration>
</plugin>

我的绑定文件:

<?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"
    version="2.1">
   
   <jaxb:bindings schemaLocation="AccommodationService_schema1.xsd"> 
       <jaxb:bindings node="/xs:schema/xs:element[@name='getLanguagesResponse']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"/>
          </annox:annotate>
      </jaxb:bindings>    
   </jaxb:bindings>
</jaxb:bindings>

XSD 部分(当我在没有上述绑定文件的情况下运行 maven build 时,它的类会正确生成):

<xs:element name="getLanguagesResponse" nillable="true" type="tns:getLanguagesResponse"/>
4

0 回答 0