Project structure
I have a project written in Java 8 and I want to update it to Java 9. So I separated the classes into 2 separate modules. Modules:
org.ggp.base
withmodule-info.java
in the directoryorg.ggp.base/src/main/java
. Its build was automated with Gradle before I started the update to Java 9. The module uses an abstract class implementation included inpl.edu.prz.klopusz
module.pl.edu.prz.klopusz
in the directorypl.edu.prz.klopusz/dolar-app/src/main/java
. I want to automate its build using Maven. The module requiresorg.ggp.base
module.
The file tree looks like:
.
├── org.ggp.base/
│ ├── build.gradle
│ └── src/
│ └── main/
│ ├── java/
│ │ ├── external/
│ │ │ └── JSON/
│ │ │ ├── JSONArray.java
│ │ │ └── JSONObject.java
│ │ ├── META-INF/
│ │ │ └── MANIFEST.MF
│ │ ├── module-info.java
│ │ └── org/
│ │ └── ggp/
│ │ └── base/
│ │ └── util/
│ │ ├── statemachine/
│ │ │ ├── MachineState.java
│ │ │ └── StateMachine.java
│ │ └── symbol/
│ └── resources/
│ └── org/
│ └── ggp/
│ └── base/
└── pl.edu.prz.klopusz/
└── dolar-app/
└── src/
└── main/
└── java/
├── module-info.java
└── pl/
└── edu/
└── prz/
└── klopusz/
└── utilities/
└── decorators
└──StateMachineDecorator.java
The contents of module-info.java
files is the following:
module org.ggp.base {
requires guava;
requires reflections;
requires jdk.httpserver;
uses org.ggp.base.util.statemachine.StateMachine;
exports org.ggp.base;
}
pl.edu.prz.klopusz/dolar-app/src/main/java/module-info.java
module pl.edu.prz.klopusz {
requires org.ggp.base;
provides org.ggp.base.util.statemachine.StateMachine
with pl.edu.prz.klopusz.utilities.decorators.StateMachineDecorator;
}
Compilation
I try to compile the project, using the following command:
javac -d out \
--module-source-path org.ggp.base/src/main/java:pl.edu.prz.klopusz/dolar-app/src/main/java \
$(find org.ggp.base/src/main/java -name *.java) \
$(find pl.edu.prz.klopusz/dolar-app/src/main/java -name *.java)
Errors
I get the following error:
org.ggp.base/src/main/java/module-info.java:1:
error: module not found on module source pathmodule org.ggp.base {
And 99 other errors for the classes inside org.ggp.base
package, each is like:
org.ggp.base/src/main/java/external/JSON/JSONObject.java:1:
error: not in a module on the module source pathpackage external.JSON;
or
org.ggp.base/src/main/java/org/ggp/base/validator/OPNFValidator.java:1:
error: not in a module on the module source pathpackage org.ggp.base.validator;
What I want
I want to get rid of the errors and compile the project. I don't have to preserve the directory structure, but when I put it all together, with 2 module-info.java
files, the compiler complainted about multiple modules. I can have it done by IntelliJ IDEA, I don't mind and I tried. But I don't know what is happening behind the scenes, and I don't know how to handle the errors either (Package is empty: org.ggp.base
).
What I've already found
It was hard to find a documentation about --module-source-path
switch in javac
command. This site is what I found. It says:
if you arrange the code in your modules such that you put the code for a module in an enclosing directory named for the module, the module source path becomes more like a simple path, as in--module-source-path Users/Me/MyProject/srcor if it is in multiple projects, use--module-source-path /Users/Me/MyProject/src:/Users/Me/MyOtherProject/src
And for Windows use backslashes and semicolons, but I'm using Linux anyway.
There is also a comment to an issue on OpenJDK bugs site, with the same error as mine, but I guess it remains unsolved.
UPDATE
-verbose
switch
I added -verbose
switch at the end of command. That is a part of what compiler says:
[parsing started SimpleFileObject[/home/sensitive/org.ggp.base/src/main/java/module-info.java]]
[parsing started SimpleFileObject[/home/sensitive/org.ggp.base/src/main/java/org/ggp/base/util/statemachine/MachineState.java]]
[parsing started SimpleFileObject[/home/sensitive/pl.edu.prz.klopusz/dolar-app/src/main/java/module-info.java]]
[parsing started SimpleFileObject[/home/sensitive/pl.edu.prz.klopusz/dolar-app/src/main/java/pl/edu/prz/klopusz/utilities/decorators/StateMachineDecorator.java]]
org.ggp.base/src/main/java/org/ggp/base/util/statemachine/MachineState.java:1: error: not in a module on the module source path
package org.ggp.base.util.statemachine;
^
[loading /modules/jdk.httpserver/module-info.class]
[loading /modules/java.base/module-info.class]
[total 263ms]
100 errors
So, I think this is not a fault of the path in --module-source-path
switch (the same behavior happens with *src/main/java
pointed out by @StephanHerrmann). It reads all the java sources it should read. There's no problem with sources in the pl.edu.prz.klopusz
module.
These are the first lines of org.ggp.base.util.statemachine.MachineState
:
package org.ggp.base.util.statemachine;
import org.ggp.base.util.gdl.grammar.GdlSentence;
import java.util.HashSet;
import java.util.Set;
public class MachineState {
//...
}
--module-source-path
want to find directories named like the modules at first level. OTOH, if I understand JEP 261 correctly, you could perhaps use a pattern like*/src/main/java
where*
would represent the module name. I haven't tried this, though. – Cess*/src/main/java
ororg.ggp.base/src/main/java:pl.edu.prz.klopusz/dolar-app/src/main/java
. – Aesculapius*/src/main/java
pattern, because of the extradolar-app
intermediate directory, which prevents matching to the module name. – Cessdolar-app
folder and splicedpl.edu.prz.klopusz
andsrc
, I used pattern'./*/src/main/java'
. Neither*/src/main/java
nor'*/src/main/java'
nororg.ggp.base/src/main/java:pl.edu.prz.klopusz/src/main/java
worked. After I used the right pattern, errors disappeared. So I guess you can make an answer out of it and I will accept it. – Aesculapiusjavac
command should look like, neither do you. For completeness sake, it isjavac -d out --module-source-path "./*/src/main/java/" $(find . -name "*.java")
, right? – Buffet$(find org.ggp.base/src/main/java -name *.java) $(find pl.edu.prz.klopusz/src/main/java -name *.java)
, because simple search in current dirfind .
doesn't work. I will add it to the answer stackoverflow.com/review/suggested-edits/21296807. – Aesculapiusfind
like I showed won't simply work; it has nothing to do withjavac
. I think you're doing something wrong with thefind
. Your edit was rejected for a different reason, I'll post my comment as an answer. – Buffet