Reputation: 596
I have 2 different projects in the same folder: com.jdojo.address
and com.jdojo.person
. The first has a simple pojo class Address
and a module-info.java
under default package:
module com.jdojo.address {
exports com.jdojo.address;
}
No errors here.
In the com.jdojo.person
project I have a Person
class that uses an Address
attribute from the previous one. The module-info.java
:
module com.jdojo.person {
requires com.jdojo.address;
exports com.jdojo.person;
}
I have an error in the requires
line:
module not found: com.jdojo.address
I have this issue both with NetBeans IDE Dev (Build 201708030001) and IntelliJ IDEA 2017.2.1.
├───com.jdojo.address
│ ├───.idea
│ │ └───inspectionProfiles
│ ├───nbproject
│ │ └───private
│ └───src
│ └───com
│ └───jdojo
│ └───address
├───com.jdojo.intro
│ ├───.idea
│ │ ├───inspectionProfiles
│ │ └───libraries
│ ├───build
│ │ ├───classes
│ │ │ └───com
│ │ │ └───jdojo
│ │ │ ├───address
│ │ │ ├───intro
│ │ │ └───person
│ │ ├───empty
│ │ └───generated-sources
│ │ └───ap-source-output
│ ├───dist
│ ├───nbproject
│ │ └───private
│ ├───src
│ │ └───com
│ │ └───jdojo
│ │ └───intro
│ └───test
├───com.jdojo.person
│ ├───.idea
│ │ └───inspectionProfiles
│ ├───nbproject
│ │ └───private
│ ├───src
│ │ └───com
│ │ └───jdojo
│ │ └───person
│ └───test
├───lib
├───mods
│ └───com.jdojo.intro
│ └───com
│ └───jdojo
│ └───intro
└───src
└───com.jdojo.intro
└───com
└───jdojo
└───intro
These are the module-info and java classes paths
C:\Java9Revealed\com.jdojo.address\src\module-info.java
C:\Java9Revealed\com.jdojo.address\src\com\jdojo\address\Address.java
C:\Java9Revealed\com.jdojo.person\src\module-info.java
C:\Java9Revealed\com.jdojo.person\src\com\jdojo\person\Person.java
Upvotes: 7
Views: 25924
Reputation: 2104
module-info.java
For me, the key was the placement of the module-info.java
as well as the naming.
I am migrating a multi module maven project from Java 11 to Java 17. In Java 11, the project builds correctly until you add the module-info.java
files. Then you may find different kinds of errors, ranging from "X module not visible" to "JavaDoc: no sources for module Y."
I generated automatically the module-info.java
files with jdeps
. This meant that the java modules were named after the maven project modules, which did not coincide with any java package name.
Renaming the module declaration to the actual java package, was a first step.
Then I tried to follow the placement of the module-info.java
file according to the answers here but at the end, having one java module per maven module, was good enough to place the module-info.java
inside the src/main/java
directory, right where the com/company/application
started for a module like com.company.application.api
(instead of where the sources were, as I was told several places).
So, not but src/main/java/com/company/application/api/module-info.java
src/main/java/module-info.java
), for a module-info.java
like this:
module com.company.application.api {
exports com.company.application.api;
}
Upvotes: 0
Reputation: 24498
Per the Quick Start guide, it is convention to put the source-code in a folder named after the module. In this case, the folder structure should be:
com.jdojo.address/src/com.jdojo.address/module-info.java
com.jdojo.address/src/com.jdojo.address/com/jdojo/address/Address.java
com.jdojo.person/src/com.jdojo.person/module-info.java
com.jdojo.person/src/com.jdojo.person/com/jdojo/person/Person.java
It is illuminating to experiment using command-line tools, independent of any IDE. I have illustrated this case here.
Upvotes: 7