I'm new to the topic of modules, and I'm following a simple example of how to create, compile and run them.
The folder structure of my project is illustrated in the following diagram:
First I typed this in a cmd window to compile the module-info.java and Task.java files:
javac --module-path mods -d feeding feeding/zoo/animal/feeding/Task.java feeding/module-info.java
Then I tried to run the code with the following:
java --module-path feeding --module zoo.animal.feeding/zoo.animal.feeding.Task
I get the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: feeding
Caused by: java.lang.module.InvalidModuleDescriptorException: Task.class found in top-level directory (unnamed package not allowed in module)
Can someone resolve this? Also, what is the role of the --module-path
option in both the java
and javac
commands?
This is the code for the class and the module descriptor:
module zoo.animal.feeding {
}
public class Task {
public static void main(String... args) {
System.out.println("All fed!");
}
}