JDK 9: JUnit 5 test compile with SpringExtension produces java.lang.NoClassDefFoundError: org/w3c/dom/ls/DocumentLS

后端 未结 2 1935
逝去的感伤
逝去的感伤 2021-01-02 18:57

I believe this problem not to be related to module exclusions in JDK 9 (as with java.se.ee), but rather with the fact that JDK 9 includes a newer version of org.w3c.dom.ls i

相关标签:
2条回答
  • 2021-01-02 19:35

    As you have correctly analyzed, the package org.w3c.dom.ls is present in the platform module java.xml. Any class on the class path that is in the same package will be ignored. That's called a split package and several fixes exist - the following two might help you.

    Patch java.xml

    You can add the classes of the Xerxes JAR to the java.xml module with --patch-module:

    java --patch-module java.xml=xerxes-4.0.0.jar ...
    

    I've never tried that with a JAR that contains some of the same classes. As I understand it, the JDK classes will then be replaced with the Xerxes classes, which means they better be a fully binary compatible replacement.

    Upgrade java.xml

    Another hope is to replace java.xml with the upgrade module path:

    The upgrade module path (--upgrade-module-path) contains compiled definitions of modules intended to be used in place of upgradeable modules built-in to the environment (compile time and run time).

    You face two problems:

    • the upgrade module path is supposed to be used only for upgradable modules (which java.xml is not), but I think I've read somewhere that that's not enforced (yet?) - didn't try it
    • the artifact you replace java.xml with needs to be fully binary compatible update - would that be the case for Xerxes?
    0 讨论(0)
  • 2021-01-02 19:35

    From what I can tell, DocumentLS is from a 2002 draft of the W3C API, it doesn't appear to have made it into a released version. It looks like xerces-2.4.0 (from 2006?) includes it but newer versions don't. So upgrading to a more recent Xerces may be needed here. If Spring really depends on DocumentLS then it will need to be updated too.

    0 讨论(0)
提交回复
热议问题