Search code examples
javajava-modulemodule-info

Automatic Module cannot be found


I cannot import org.json as an Automatic Module.

I've set up a very simple test project with the following directory structure:

src\module-info.java
src\uk\co\stikman\broken\Example.java
lib\json-20200518.jar

module-info:

module uk.co.stikman.broken {
    requires json;
}

I try to run javac as:

javac --module-path lib -d output src\module-info.java src\uk\co\stikman\broken\Example.java

Which returns the error:

src\module-info.java:2: error: module not found: json
        requires json;

org.json is not a modular project, and it's my understanding that including it on the module-path would turn it into an "Automatic Module" with its name being derived from the filename json-20200518.jar

What am I doing wrong/not understanding?


Solution

  • Change

    requires json;
    

    to

    requires org.json;
    

    The reason for that is specified in the META-INF of the artifact.

    Automatic-Module-Name: org.json