无法访问类jdk.xml.internal.JdkXmlUtils [英] cannot access class jdk.xml.internal.JdkXmlUtils

查看:129
本文介绍了无法访问类jdk.xml.internal.JdkXmlUtils的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为hybris/SAP-Commerce(2005)更新一个旧的Company-intern扩展名.这是使用API​​的扩展.

I'm updating an old Company-intern extension for hybris/SAP-Commerce (2005). it's an extension to consume an API.

我不知道扩展名多大.

但是,在将其应用于Java 11时,我发现了这样的问题().

However, while applying it to java 11, I spot problems like this (Java 11: import javax.xml.ws.WebFault: "Cannot resolve symbol ws").

重新运行命令./hybrisserver.sh后,给定的(.只读).jar"文件引发以下异常:

After rerun the command ./hybrisserver.sh, a given (read only) '.jar' file throws follow exception:

Failed to instantiate [<class from given .jar>]:
            Constructor threw exception;
        nested exception is java.lang.IllegalAccessError:
            class com.sun.org.apache.xml.internal.resolver.Catalog (in unnamed module @0x9a92113) cannot access class jdk.xml.internal.JdkXmlUtils (in module java.xml) because module java.xml does not export jdk.xml.internal to unnamed module @0x9a92113

我认为这可能是jdk问题,所以我尝试了不同的发行版.(我正在使用sdkman处理Manjaro Linux KDE 20.1)遵循我测试过的发行版:

I thought it could be a jdk problem, so I tried different distributions. (I'm working on Manjaro Linux KDE 20.1 with sdkman) Follow distributions I've tested:

 Vendor        | Version      | Dist    | Identifier
--------------------------------------------------------
 AdoptOpenJDK  | 11.0.8.j9    | adpt    | 11.0.8.j9-adpt      
 Java.net      | 11.0.8       | open    | 11.0.8-open       
 SAP           | 11.0.8       | sapmchn | 11.0.8-sapmchn 

每一个都引发相同的错误

Each of it throw the same error

推荐答案

这不是JDK错误.您尝试构建的代码实际上是一个问题.该代码使用JVM内部软件包中的类.它不需要这样做.

This is not a JDK bug. It is actually a problem with the code you are trying to build. The code is using a class in a JVM internal package. It shouldn't need to do that.

执行此操作始终是一个坏主意,因为内部包中的类如有更改,恕不另行通知.旧的Java文档中包含警告,提示您不要这样做.

It was always a bad idea to do this, since classes in internal packages are subject to change without any notice. The old Java documentation included warnings to say not to do this.

从Java 9开始,模块系统(默认情况下)将阻止应用程序代码访问内部API.这就是您在这里遇到的问题.

As of Java 9, the module system will (by default) prevent application code from accessing internal APIs. And that is what you are running into here.

有两种解决方法:

  • 更好的方法是修改您尝试编译的代码,使其不再依赖于该类.(我们无法提供有关如何做到这一点的建议,而无需看到您的代码...)

  • The better way is to modify the code you are trying to compile so that it no longer depends on that class. (We can't offer suggestions as to how to do this without seeing your code ...)

另一种方法是在 java 命令行中使用-add-opens 选项来中断模块封装以允许访问该类.对于不使用模块的代码,以下应该执行此操作.

The other way is to use --add-opens options in the java command line to break module encapsulation to allow access the class. The following should do it for code that doesn't use modules.

--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED

此方法应被视为短期解决方法.您正在使用的内部API 可以在下一个Java版本中更改或删除.

This approach should be viewed as a short term work-around. The internal API you are using could be changed or removed with the next Java release.

这篇关于无法访问类jdk.xml.internal.JdkXmlUtils的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆