1

I'm currently migrating a project to Java 11 (i.e. >= 9) and because JavaFX seems not to work without modules, anymore, I'm currently adding module-info.java files to all sub-projects. But I get the following error:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/mangu/workspace/cloudstore.2/co.codewizards.java9test.project1/src/main/java/module-info.java:[6,21] module not found: org.slf4j
[INFO] 1 error

I'm running OpenJDK 11.0.3, Maven 3.6.1 (embedded in Eclipse 2019-06) and I definitely have the dependency for the module org.slf4j declared in my pom.xml!

In order to simplify things, I created a little, minimal test-project causing the same error.

Here's the test-project's pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>co.codewizards.java9test</groupId>
    <artifactId>co.codewizards.java9test.project1</artifactId>
    <version>0.1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>9</maven.compiler.source>
        <maven.compiler.target>9</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.8.0-beta4</version>
        </dependency>
    </dependencies>

</project>

I tried both: 1.8.0-beta4 and 2.0.0-alpha0. Eclipse shows me an existing module-info.class in both JARs (i.e. currently inside slf4j-api-1.8.0-beta4.jar).

Here's the module-info.java:

module co.codewizards.java9test.project1 {

    requires java.base;
    requires java.se;

    requires org.slf4j;

}

And here's the output from mvn clean install -Dmaven.test.skip=true -X (but run inside Eclipse): mvn.log

Any idea what I'm doing wrong?

Update: I just uploaded the little test project: co.codewizards.java9test.project1.7z

Marco
  • 304
  • 4
  • 6
  • I had sort of [related issue](https://stackoverflow.com/questions/57259605/patching-module-raises-module-not-found-error) when compiler printed `module not found` error, but when I tried to patch a module. In my case the module was not found because it simply was not contained in the module path. – St.Antario Jul 31 '19 at 22:02
  • So I'd advise you to check a module path. – St.Antario Jul 31 '19 at 22:02
  • Thanks for your reply, but isn't the module-path automatically generated from the dependencies just like the class-path is? Or do I have to enable this somehow? I already checked the documentation of the [maven-compiler-plugin](https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html), but there's nothing written about the module-path. The only thing mentioning modules in the context of the maven-compiler-plugin is [this](https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html), which does not mention any special settings, either. – Marco Aug 01 '19 at 02:55

2 Answers2

2

Your maven logs show slf4j-api being placed on the classpath, not modulepath.

You need to upgrade the version of maven-compiler-plugin, as modulepath is supported only since version 3.6, whereas your build uses version 3.1.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
2

I was getting the same issue due to older verion of slf4j was coming from one of dependency in pom. So I resolved it by adding below slf4j dependency to my pom :

      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.29</version>
    </dependency>

module-info:

module my.service {

requires org.slf4j; 
}
Pukhraj soni
  • 1,832
  • 2
  • 17
  • 11