javajava-11modularityjava-module

Why am I getting error during javac module compilation?


When trying to compile my module moduleA with the following command

javac --module-source-path src -d out -m moduleA

I get the following error

error: module moduleA not found in module source path

The structure:

src 
│   module-info.java
│ 
└───moduleA
    └───pack1
            Main.java

module-info.java :

module moduleA {
}

Solution

  • --module-source-path is usually used to compile multiple modules at once. But of course, you can compile a single module with it if you want. However, you have to move the source files to the directory with the module name:

    src
    └───moduleA
        │───module-info.java
        └───moduleA
            └───pack1
                └───Main.java
    

    Also, you should fix the command line which runs your module:

    java --module-path out -m moduleA/moduleA.pack1.Main