当前位置: 首页 > 知识库问答 >
问题:

为什么使用cxf-xjc-plugin从xsd生成代码(java)在JDK11(amazon)上不起作用,而在Java8上却起作用[重复]

堵恺
2023-03-14
       ...
           <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

共有1个答案

呼延高超
2023-03-14

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

我根据这个stackoverflow答案解决了这个问题,所以我最终添加了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
 类似资料:
  • 我正在学习代码通过yt黑客客户端,但我有问题理解一些东西,。https://www.youtube.com/watch?v=-vh8wuja1re&t=171s大约2到3分钟,他将公共静态void启动放到一个他命名为“client”类中。然后他上了Minecraft的课,在某一行上了Client.Startup。我想知道为什么这会起作用,因为这两个类都不是主要的类,我尝试在一个不同的正常Java

  • 因此,下面的代码,从txt文件中取序列号作为参数,在我的计算机上正常工作。每个数字都写在一行上。下面是代码: 但它在CodeEval中不起作用。站点编译器是这么说的: Fontconfig错误:无法加载默认配置文件线程“main”java.awt.HeadLessException:未设置X11显示变量,但此程序执行了需要它的操作。在java.awt.GraphicsEnvironment.Che

  • 问题内容: 我可以使用以下代码和Java 8对用户列表进行排序,而不会出现任何问题: 现在,我改用Java 7,但在Eclipse上没有看到错误。但是现在,在Java 7下运行时出现此错误: 如何解决? 问题答案: Java 7(以及Java 8的早期版本)和Java 8u20之间的工作方式有所不同(Holger指出,版本8032636)。 Java 7 指定: 此实现将指定的列表转储到数组中,对

  • 问题内容: 我想在chromedp上使用代理,但是代理似乎不起作用,尝试了chromedp.ProxyServer 使用代理后,我得到了公共IPeven。无错误/警告 问题答案: 试试这个:

  • 通过选择,,和,我创建了一个全新的Spring初始化项目。 我做了一个小项目: 我试着将三个人保存到数据库中。保存方法只返回需要执行的Mono。如果我尝试通过简单的订阅来执行它,一切都很好: 但是,当我使用而不是时,应用程序挂起: 如果我手动查询数据库,我会看到Jim已被保存,但Jack和John未被保存。 这是窃听器,还是我做错了什么?我希望在代码进一步发展之前保证用户在数据库中,所以我真的很想

  • 拿我正在试验的这个非常简单的框架来说(这样我就可以更深入地学习JavaScript的函数原型。) 这工作很棒。控制台的输出是: 对象{ui:对象,操作:"单击设置openSidebar",函数:对象,运行:函数} 但是,当我尝试这样做时: 在openSidebar()中的的上下文是openSidebar(又名bind没有效果)。控制台输出: 对象{openSidebar:function} 但是,