如何更新JDK中使用的JAXB RI版本?

时间:2018-04-25 08:13:39

标签: java java-8 jaxb java-7 jaxb2

当我用JDK 8编译我的XSD时,我得到了我期望的输出。

当我用JDK 7编译我的XSD时,似乎没有读取我的binding.xjb文件。

我很确定这是jaxb-v2之间修复的众多缺陷之一

  • JDK7首次发布JAXB RI 2.2.4-1

  • JDK8首次发布JAXB RI 2.2.8

发行说明:JAXB

有人可以帮我解决如何更新JDK使用的JAXB RI的版本吗?

我正在使用Maven构建并使用...

的依赖项
  <dependency>
    <groupId>org.jvnet.jaxb2_commons</groupId>
    <artifactId>jaxb2-basics-runtime</artifactId>
    <version>0.6.4</version>
  </dependency>

我使用的插件是......

  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.13.3</version>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <catalog>target/classes/catalog.cat</catalog>
          <strict>false</strict>
          <extension>true</extension>
          <schemaIncludes>
            <include>*.xsd</include>
          </schemaIncludes>
          <bindingIncludes>
            <include>*.xjb</include>
          </bindingIncludes>
          <generatePackage>com.pcmsgroup.v21.esi.deviceservice.bean</generatePackage>
          <args>
            <arg>-XtoString</arg>
            <arg>-Xequals</arg>
            <arg>-XhashCode</arg>
            <arg>-Xinheritance</arg>
            <arg>-Xcopyable</arg>
            <arg>-XenumValue</arg>
            <arg>-Xannotate</arg>
          </args>
          <plugins>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics</artifactId>
              <version>0.9.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>
    <configuration>
      <catalog>target/classes/catalog.cat</catalog>
      <strict>false</strict>
      <extension>true</extension>
      <schemaIncludes>
        <include>*.xsd</include>
      </schemaIncludes>
      <bindingIncludes>
        <include>*.xjb</include>
      </bindingIncludes>
      <generatePackage>com.jeff.bean</generatePackage>
      <args>
        <arg>-XtoString</arg>
        <arg>-Xequals</arg>
        <arg>-XhashCode</arg>
        <arg>-Xinheritance</arg>
        <arg>-Xcopyable</arg>
        <arg>-XenumValue</arg>
        <arg>-Xannotate</arg>
      </args>
      <plugins>
        <plugin>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics</artifactId>
          <version>0.9.5</version>
        </plugin>
        <plugin>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics-annotate</artifactId>
          <version>0.6.5</version>
        </plugin>
      </plugins>
    </configuration>
  </plugin>

我可能接近这个错误,也许我需要看看org.jvnet.jaxb2.maven2:maven-jaxb2-plugin

这显示了JDK和JDK 8运行之间的区别。 在左侧,它似乎忽略binding.xjc文件,因此不知道枚举大小。 JDK 7 vs JDK 8

我们还可以看到生成的java类有不同的类型。 Generated java file

此外,它在JDK 8中生成Adapter类,但在JDK 7中不生成。 Generated files

1 个答案:

答案 0 :(得分:0)

很少有建议:

  1. args 在两个地方定义。一个在/plugin/executions/execution/configuration/args下,一个在/plugin/configuration/args下。您可以在/plugin/configuration/args
  2. 中获取它
  3. 在/ plugin / configuration下,有两个属性 schemaDirectory bindingDirectory 。在上面的插件使用中无法看到,xsds和xjbs都在资源目录中吗?
  4. 您也可以尝试设置这些参数: forceRegenerate = true和 cleanPackageDirectories = false。
  5. 只需提及示例插件定义以供参考,您可以修剪不需要的详细信息。

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.3</version>
        <configuration>
            <generatePackage>com.some.sample.package</generatePackage>
            <schemaDirectory>src/main/resources/xsd</schemaDirectory>
            <bindingDirectory>src/main/resources/xjb</bindingDirectory>
            <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
            <extension>true</extension>
            <args>
                <arg>-no-header</arg>
                <arg>-Xxew</arg>
                <arg>-Xxew:instantiate lazy</arg>
                <arg>-Xxew:delete</arg>
                <arg>-XtoString</arg>
                <arg>-Xequals</arg>
                <arg>-XhashCode</arg>
                <arg>-Xvalue-constructor</arg>
                <arg>-Xfluent-api</arg>
                <arg>-Xannotate</arg>
            </args>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>${jaxb2.basics.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-fluent-api</artifactId>
                    <version>${jaxb2.fluentapi.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-value-constructor</artifactId>
                    <version>${jaxb2.value.constructor.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-annotate</artifactId>
                    <version>${jaxb2.basics.annotate.version}</version>
                </plugin>
            </plugins>
        </configuration>
        <executions>
            <execution>
                <id>abc.xsd</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaIncludes>
                        <include>abc.xsd</include>
                    </schemaIncludes>
                    <bindingIncludes>
                        <include>abc.binding.xml</include>
                    </bindingIncludes>
                    <generatePackage>com.some.sample.package.transfer</generatePackage>
                    <removeOldOutput>false</removeOldOutput>
                    <forceRegenerate>true</forceRegenerate>
                    <cleanPackageDirectories>false</cleanPackageDirectories>
                </configuration>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>com.github.jaxb-xew-plugin</groupId>
                <artifactId>jaxb-xew-plugin</artifactId>
                <version>${jaxb.xew.plugin.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-xjc</artifactId>
                <version>${jaxb.xjc.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-osgi</artifactId>
                <version>${jaxb.xjc.version}</version>
            </dependency>
        </dependencies>
    </plugin>
    
    
    <jaxb2.basics.version>0.9.2</jaxb2.basics.version>
    <jaxb.xew.plugin.version>1.1</jaxb.xew.plugin.version>
    <jaxb.xjc.version>2.2.6</jaxb.xjc.version>
    <jaxb2.fluentapi.version>3.0</jaxb2.fluentapi.version>
    <jaxb2.value.constructor.version>3.0</jaxb2.value.constructor.version>
    <javax.xml.bind.version>2.2.6</javax.xml.bind.version>
    <jaxb2.basics.annotate.version>1.0.4</jaxb2.basics.annotate.version>