I migrate a project from Java 8
to Java 11
, and I got some trouble in generating code from XSD
using the cxf-xjc-plugin.
Even that I did upgrade cxf-xjc-plugin
to version 3.3.0
, still getting exceptions while building the project
my 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>
...
Stack trace
[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
Hope this help others who face the same issue,
I solved this issues base on this stackoverflow answer, so I ended up adding JAXB dependancies like so:
...
<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>
...
My project build passe, but on runtime I get some warnings:
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
and I read here that this issue will be solver on the future version of JAXB