0

I've problem replace commons-logging with jcl-over-slf4j in Java 9 Module System. I've exclude commons-logging from maven and add jcl-over-slf4j as dependency:

  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-configuration2</artifactId>
    <version>2.3</version>
    <exclusions>
      <exclusion>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
      </exclusion>
    </exclusions>
  </dependency>

  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.8.0-beta2</version>
  </dependency>

As I can see, the commons-configuration2 is an auto named module and the jcl-over-slf4j is an application module.

If I leave the module jcl-over-slf4j out of module-info.java, I got this NoClassDefFoundError error, the jcl-over-slf4j is on the classpath somehow the library can't see it:

 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/Log
at org.apache.commons.configuration2@2.3/org.apache.commons.configuration2.io.FileSystem.<clinit>(FileSystem.java:37)

If I add the jcl-over-slf4j to the module-info.java, I got this illegal access error,:

requires transitive org.apache.commons.logging;

Which org.apache.commons.logging module is in fact the jcl-over-slf4j module.

xception in thread "main" java.lang.IllegalAccessError: class org.apache.commons.configuration2.io.ConfigurationLogger (in module org.apache.commons.configuration2) cannot access class org.apache.commons.logging.impl.NoOpLog (in module org.apache.commons.logging) because module org.apache.commons.logging does not export org.apache.commons.logging.impl to module org.apache.commons.configuration2
at org.apache.commons.configuration2@2.3/org.apache.commons.configuration2.io.ConfigurationLogger.newDummyLogger(ConfigurationLogger.java:115)

Which I don't understand, the commons-configuration2 shoulde be able to access it, and I'm stuck here. Any help is welcome.

LongkerDandy
  • 125
  • 1
  • 5
  • Try to run java with `--add-opens org.apache.commons.logging=ALL-UNNAMED` – Ivan Sep 19 '18 at 11:56
  • @Ivan I tried --add-opens --add-exports --add-reads to the params,all of them gave the same exception – LongkerDandy Sep 19 '18 at 13:37
  • `--add-exports org.apache.commons.logging/org.apache.commons.logging.impl=org.apache.commons.configuration2` can probably be used to workaround this but I think it needs a deeper understand as to why org.apache.commons.logging doesn't export this package to org.apache.commons.configuration2. The most obvious question is how was org.apache.commons.configuration2 compiled with references to public types in org.apache.commons.logging.impl when that package is not exported. – Alan Bateman Sep 19 '18 at 13:43

0 Answers0