【问题标题】:switching from java 8 to java 11从 Java 8 切换到 Java 11
【发布时间】:2021-09-25 04:39:24
【问题描述】:

切换到 java 11 后,com.sun.org.apache.xerces.internal.dom#DOMInputImpl() 出现问题。在此代码中:

@Override
public LSInput resolveResource(final String type,
                               final String namespaceURI, final String publicId, String systemId,
                               final String baseURI) {
    final LSInput input = new DOMInputImpl();
    if (systemId.equals(this.systemId)) {
        try {
            input.setByteStream(xsdFile.getInputStream());
        } catch (IOException e) {
            log.error("Error to get classpath resource for schema");
        }
    }
    return input;
}

编译时出现错误:

错误:(8,42) java: com.sun.org.apache.xerces.internal.dom 包不可见

我尝试添加到 maven-surefire-plugin --add-exports... 但它没有帮助我

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin.version}</version>
            <configuration>
                <argLine>--illegal-access=permit</argLine>
                <argLine>--add-exports java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED</argLine>
                <argLine>-Dillegal-access=permit</argLine>
            </configuration>
        </plugin>

【问题讨论】:

  • 也许值得一试&lt;argLine&gt;--add-modules java.xml&lt;/argLine&gt;

标签: java java-8 java-11 maven-surefire-plugin


【解决方案1】:

您应该使用原始的 xerces 实现。

这里也回答了这个问题:https://github.com/adoptium/adoptium-support/issues/199#issuecomment-717008260

在 JDK 9 中,引入了 Java 平台模块系统。作为其中的一部分,对最初不应该使用的内部 API 的访问被关闭。解决方案:升级您的依赖项,停止使用内部 API。对于 Xerces,可以从 https://xerces.apache.org/ 获得该库。

【讨论】:

    猜你喜欢
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2019-09-20
    • 2020-06-09
    • 1970-01-01
    • 2019-01-24
    相关资源
    最近更新 更多