我将一个项目从 迁移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