首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jaxb2-annotate-plugin无法处理剧集

Jaxb2-annotate-plugin无法处理剧集
EN

Stack Overflow用户
提问于 2018-02-01 19:13:55
回答 1查看 247关注 0票数 0

我正在尝试对生成的JAXB类强制执行枚举验证,但在绑定它们时遇到了一些问题。

基本的XSD设置是:

代码语言:javascript
复制
-enumsXSD
-2 other XSDs that import this XSD

为了防止类的重复,我使用了事件,但在enumsXSD中添加注释时,这看起来并不好用

代码语言:javascript
复制
com.sun.istack.SAXParseException2: compiler was unable to honor this annox:annotateEnumValueMethod customization. It is attached to a wrong place, or its inconsistent with other bindings.

[ERROR] Error while generating code.Location [ file:somewhere/generic.episode{64,99}].
com.sun.istack.SAXParseException2: (the above customization is attached to the following location in the schema) 

代码:

代码语言:javascript
复制
<plugins>
      <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.3</version>
        <configuration>
          <extension>true</extension>
          <args>
            <arg>-Xannotate</arg>
          </args>
          <plugins>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics-annotate</artifactId>
              <version>1.0.4</version>
            </plugin>
          </plugins>
        </configuration>
        <executions>
          <!--GENERIC ENUMS -->
          <execution>
            <id>ENUMS</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <extension>true</extension>
            <generatePackage>com.foo.generic.enums</generatePackage>
              <generateDirectory>${project.build.directory}/generated-sources/xjc1/generic</generateDirectory>
              <!-- Define the directory where we should find the XSD files -->
              <schemaDirectory>
                src/main/resources/dtd/generic
              </schemaDirectory>
              <schemaIncludes>
                <source>enums.xsd</source>
              </schemaIncludes>
              <episodeFile>
                ${project.build.directory}/generated-sources/xjc1/generic/META-INF/generic.episode
              </episodeFile>
            </configuration>
          </execution>
          <execution>
            <id>A_XSD</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <extension>true</extension>
              <bindingDirectory>${project.build.directory}/generated-sources/xjc1/generic/META-INF</bindingDirectory>
              <bindingIncludes>
                <include>generic.episode</include>
              </bindingIncludes>

              <!-- Set the package of the generated code -->
              <generatePackage>com.foo.something</generatePackage>
              <generateDirectory>${project.build.directory}/generated-sources/xjc1/a_something</generateDirectory>

              <!-- Define the directory where we should find the XSD files -->
              <schemaDirectory>
                src/main/resources/dtd/someplace/a/
              </schemaDirectory>
              <schemaIncludes>
                <source>*.xsd</source>
              </schemaIncludes>
            </configuration>
          </execution>
     </executions>
   <plugin>
</plugins>

在枚举XSD中

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema elementFormDefault="qualified" id="commonEnums"
           targetNamespace="http://foo.com/xsd/commons/enum"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           jaxb:version="2.1"
           xmlns:annox="http://annox.dev.java.net"
           jaxb:extensionBindingPrefixes="annox">
<xs:simpleType name="bulletinCategory">
    <xs:annotation>
      <xs:appinfo>
        <annox:annotateEnumValueMethod>@java.lang.Deprecated</annox:annotateEnumValueMethod>
      </xs:appinfo>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="valueA" />
      <xs:enumeration value="valueB" />
      <xs:enumeration value="valueC" />
    </xs:restriction>
  </xs:simpleType>
</xs>

理想情况下,@deprecated应该是@XmlJavaTypeAdapter(FooAdapter.class),但我想让我们从小开始。

EN

回答 1

Stack Overflow用户

发布于 2018-02-04 00:53:26

问题可能是您已经将定制直接包含到enums.xsd中。因此,当您编译其他模式时,也会考虑这些定制。

但是,由于您似乎还使用了enums.xsd as事件,这有效地阻止了枚举类的生成。如果没有枚举类,则不能应用定制,因此它们不会被标记为“已识别”,这会产生您得到的错误。

要解决此问题,在编译enums.xsd时,只需将定制内容移动到单独的绑定文件中,并在编译期间使用它。

然后,在编译其他模式时,可以使用enums.xsd作为enums.xsd,但不要将该绑定文件与for的自定义一起使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48561387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档