Question Details

No question body available.

Tags

java javac java-module java-platform-module-system

Answers (1)

Accepted Answer Available
Accepted Answer
May 2, 2026 Score: 3 Rep: 294,830 Quality: Expert Completeness: 80%

The host system is free to determine...

"Free" is the keyword here. The Java Language Specification leaves it up to the implementation to determine how this is done.

The javac compiler has the --module-source-path option to let you specify where your modules are. javac would look for module-info.java files and the modules declared therein would be considered "observable".

Here is an example project structure

project
└── mymodule
    ├── com
    │   └── example
    │       └── foo
    │           └── Main.java
    └── module-info.java

You can compile this like this:

cd project
javac --module-source-path . -d out mymodule/com/example/foo/Main.java

Here I used . as the module source path, and javac will find ./mymodule/module-info.java. This file should be a ModularCompilationUnit as the JLS calls it. e.g.

module mymodule {

}

To run the output binary, use the --module-path option instead.

java --module-path out -m mymodule/com.example.foo.Main 

Now printing Main.class.getModule() will produce module mymodule.