gpt4 book ai didi

java - 为什么使用 cxf-xjc-plugin 从 xsd 生成代码 (java) 在 jdk 11 (amazon) 上不起作用,但在 java 8 上却起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:38 25 4
gpt4 key购买 nike

我从 Java 8 迁移了一个项目至Java 11 ,并且我在从 XSD 生成代码时遇到了一些麻烦。使用cxf-xjc-plugin.

即使我升级了cxf-xjc-plugin至版本3.3.0 ,在构建项目时仍然遇到异常

我的pom.xml

       ...
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot>
<xsdOptions>
<xsdOption>
<xsd>src/main/resources/xsd/leehwak.xsd</xsd>
<packagename>fr.lee.hwak.batch.input</packagename>
<extensionArgs>
<arg>-encoding</arg>
<arg>UTF-8</arg>
</extensionArgs>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
...

堆栈跟踪

[ERROR] C:\Users\Achraf\IdeaProjects\lee\lee-batch\target\null [-1:-1]: Failed to create model
com.sun.istack.SAXParseException2; Failed to create model
at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:64)
at org.apache.cxf.maven_plugin.XSDToJavaRunner.loadModel(XSDToJavaRunner.java:241)
at org.apache.cxf.maven_plugin.XSDToJavaRunner.run(XSDToJavaRunner.java:177)
at org.apache.cxf.maven_plugin.XSDToJavaRunner.main(XSDToJavaRunner.java:375)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.cxf.maven_plugin.XSDToJavaRunner.loadModel(XSDToJavaRunner.java:239)
... 2 more
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:83)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:117)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:88)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:366)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:121)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:76)
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:72)
... 12 more
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:83)
at com.sun.tools.xjc.reader.xmlschema.BindingComponent.getClassSelector(BindingComponent.java:35)
at com.sun.tools.xjc.reader.xmlschema.ColorBinder.<init>(ColorBinder.java:32)
at com.sun.tools.xjc.reader.xmlschema.BindGreen.<init>(BindGreen.java:33)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:72)
... 20 more
Caused by: java.lang.ExceptionInInitializerError
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:44)
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:29)
at com.sun.xml.bind.v2.model.core.Adapter.<init>(Adapter.java:84)
at com.sun.tools.xjc.model.CAdapter.<init>(CAdapter.java:52)
at com.sun.tools.xjc.model.TypeUseFactory.adapt(TypeUseFactory.java:65)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.makeAdapted(CBuiltinLeafInfo.java:162)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.<clinit>(CBuiltinLeafInfo.java:358)
at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.<clinit>(SimpleTypeBuilder.java:867)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:72)
at com.sun.tools.xjc.reader.xmlschema.DefaultClassBinder.<init>(DefaultClassBinder.java:68)
at com.sun.tools.xjc.reader.xmlschema.ClassSelector.<init>(ClassSelector.java:184)
... 25 more
Caused by: java.lang.IllegalStateException: ReflectionNavigator.getInstance can't be found
at com.sun.tools.xjc.model.nav.Utils$1.run(Utils.java:54)
at com.sun.tools.xjc.model.nav.Utils$1.run(Utils.java:46)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.tools.xjc.model.nav.Utils.<clinit>(Utils.java:45)
... 40 more


[ERROR] C:\Users\Achraf\IdeaProjects\lee\lee-batch\src\main\resources\xsd\leehwak.xsd [0:0]: Failed to create model

最佳答案

希望这可以帮助其他面临同样问题的人,

我根据这个stackoverflow answer解决了这个问题,所以我最终添加了 JAXB 依赖项,如下所示:

...
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.8</version>
</dependency>
...

我的项目构建已通过,但在运行时我收到一些警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

我读到here该问题将在 JAXB 的 future 版本中得到解决

关于java - 为什么使用 cxf-xjc-plugin 从 xsd 生成代码 (java) 在 jdk 11 (amazon) 上不起作用,但在 java 8 上却起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58646738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com