Skip to content

org.json cannot be resolved to a module?

I’m learning Java. To read JSON in my application, I downloaded this JSON library; which is an automatic module.

I included that library in my module descriptor like:

module art
    exports  art.anixt;
    exports  art.coartl;
    exports  art.runeape;
    requires org.json;    // org.json cannot be resolved to a moduleJava(8389908)

My settings.json in vscode:

    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    "java.format.settings.url": "Format.xml",
    "java.format.settings.profile": "style",
    "java.project.referencedLibraries": [
        "lib/**/*.jar" // jar file showing in Referenced library(see screenshot)

How do I include the jar file in my module and import it into my Java file?





TL;DR — As this unresolved ‘Cannot be resolved’ errors in projects with issue reports, vscode is brain dead when it comes to JPMS and

The long-winded version

From my own experience, I can personally vouch for what the reporter of the above-linked vscode issue reports…

…I’ve tried both Gradle and Maven…

…I find that Gradle and Maven will automatically refresh the classpath file and remove my modifications to it, which will bring back the errors…

…there needs to be module path information set in the classpath file in order for Eclipse to be happy, but there is no good way to do with that from Gradle or Maven…

Proof that it’s a vscode issue is that the exact same project — unchanged except for the removal of your comment — compiles perfectly fine in IntelliJ…

No problems in

Since your project uses neither Maven nor Gradle — opting instead to use file-based dependency mgt with the jar in the lib folder — you’re in even worse shape because you’ve eliminated the option of applying any JPMS-enabling plugins that could resolve the issue.

For example, by adding the following pom.xml with the appropriate configuration for the maven-compiler-plugin to my experimental version of your project…


…Maven does its magic and processes the successfully…

No problems in

I’ve successfully resolved other Stackers’ JPMS woes by helping them apply that mrJar plugin mentioned in that vscode bug report. So if you’re open to using Gradle instead of Maven, I could likewise advise you on how to configure that plugin too.

User contributions licensed under: CC BY-SA
10 People found this is helpful