当前位置: 首页 > 面试题库 >

XJC Maven插件(jaxb2-maven-plugin)Java 11迁移问题

明利
2023-03-14
问题内容

我目前正在从事Java 11迁移项目,其中jaxb2-maven-plugin已用于XJC任务。由于JDK
11版本中没有XJC可执行文件,因此出现以下错误。

    [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc-schema1) on project paymaster-service: Execution xjc-schema1 of goal org.codehaus.mojo:jaxb2-maven-plugin:2.2
:xjc failed: A required class was missing while executing org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc: com/sun/codemodel/CodeWriter
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:jaxb2-maven-plugin:2.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/voletis/.m2/repository/org/codehaus/mojo/jaxb2-maven-plugin/2.2/jaxb2-maven-plugin-2.2.jar
[ERROR] urls[1] = file:/C:/Users/voletis/.m2/repository/javax/xml/bind/jaxb-api/2.2.11/jaxb-api-2.2.11.jar
[ERROR] urls[2] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-core/2.2.11/jaxb-core-2.2.11.jar
[ERROR] urls[3] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
[ERROR] urls[4] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
[ERROR] urls[5] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-jxc/2.2.11/jaxb-jxc-2.2.11.jar
[ERROR] urls[6] = file:/C:/Users/voletis/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M3/qdox-2.0-M3.jar
[ERROR] urls[7] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[8] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[9] = file:/C:/Users/voletis/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] urls[10] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[11] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[12] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[13] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[14] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.5/plexus-compiler-api-2.5.jar
[ERROR] urls[15] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[16] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] : com.sun.codemodel.CodeWriter
[ERROR] -> [Help 1]
[ERROR]

下面是我的pom.xml

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxb2-maven-plugin</artifactId>
   <version>2.2</version>
   <executions>
      <execution>
         <id>xjc-schema1</id>
         <goals>
            <goal>xjc</goal>
         </goals>
         <configuration>
            <target>2.2</target>
            <schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
            <packageName>app.test.services.submitpayment.request</packageName>
            <clearOutputDir>false</clearOutputDir>
         </configuration>
      </execution>
</plugin>

根据Java 11的要求,我添加了必要的依赖项,例如JAXB,JAXB-IMPL等。但是仍然无法解决问题。您对此有任何建议的解决方法吗?预先感谢。


问题答案:

我通过以下参考链接解决了此问题。

https://github.com/davidmoten/jax-maven-
plugin

根据上面的教程参考,我已经如下修改了我的插件,并且我能够解决此问题。

<plugin>
   <groupId>com.github.davidmoten</groupId>
   <artifactId>jax-maven-plugin</artifactId>
   <version>VERSION_HERE</version>

   <executions>
      <execution>
         <id>xjc-schema1</id>
         <goals>
            <goal>xjc</goal>
         </goals>
         <configuration>
            <target>2.2</target>
            <schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
            <packageName>app.test.services.submitpayment.request</packageName>
            <clearOutputDir>false</clearOutputDir>
         </configuration>
      </execution>
   </executions>
</plugin>


 类似资料:
  • 这是我的相关部分pom.xml 我使用的是JDK1.7。运行时,会生成对给定xsd文件的解析和相应的JAXB类,但我的要求是生成单独的类,而不是当前生成的内部类。为此,我有一个非常通用的绑定。xml 但是在运行jaxb2插件xjc时;正在生成带有内部静态类的JAXB类。有什么建议吗 `

  • 问题内容: 我想将多个xsd模式解组到 同一 文件夹下的不同程序包中。我尝试了两个插件,并且似乎都可以在这两种配置下正常工作,但是在使用maven- jaxb2-plugin的情况下,eclipse插件会无限期地生成类(由于= true),但是如果我不指定forceRegenerate,它将不会生成运行时完全没有第二组和第三组类,我的配置是否有问题? jaxb2-maven-插件 maven-ja

  • 在使用maven-jaxb2插件从xsd生成Java代码时,我遇到了以下错误,使用命令行中的xjc,这些代码都运行良好。有人知道如何调试maven-jaxb2插件吗?

  • 我有多个xsd模式,我想将它们解组到同一文件夹下的不同包中。我尝试了这两个插件,两个插件似乎都能很好地处理这两种配置,但在maven-jaxb2-plugin的情况下,eclipse插件会无限期地生成类(因为=true),但是如果我没有指定forceRegenate,当我运行我的配置有任何问题吗? jaxb2 maven插件 maven-jaxb2-plugin 以及build helper ma

  • 我使用Maven3.3.3和maven-jaxb2-plugin Version0.12.1从XSD模式生成java类。XSD所在的地址返回HTTP 302,插件抛出: 是否可以指定xjc编译器遵循302到正确的链接,或者不去尝试下载XSD?

  • 我正在尝试构建我的项目,因为我遇到了一个名为[error]的错误,无法执行目标组织。科德豪斯。mojo:jaxb2-maven插件:2.4:xjc(一)on project tg tems ota common service::MojoExecutionException:NoSchemasException- 我们使用的是java8、apache maven 3.6.3、jaxb2插件2.4