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:
For completeness sake, the complete javac
command is as follows:
javac -d out --module-source-path "./*/src/main/java/" $(find . -name "*.java")
Based on the official tutorial from OpenJDK (slightly modified directory structure shown below), and OpenJDK version "11.0.1", the above command javac
works for me:
.
├── com.greetings
│ └── src
│ └── main
│ └── java
│ ├── com
│ │ └── greetings
│ │ └── Main.java
│ └── module-info.java
├── org.astro
│ └── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── org
│ └── astro
│ └── World.java
├── out
│ ├── classes
│ │ ├── com.greetings
│ │ │ ├── com
│ │ │ │ └── greetings
│ │ │ │ └── Main.class
│ │ │ └── module-info.class
│ │ └── org.astro
│ │ ├── module-info.class
│ │ └── org
│ │ └── astro
│ │ └── World.class
│ └── lib
│ ├── com.greetings.jar
│ └── org.astro@1.0.jar
As per JEP 261 the --module-source-path
option (for compilation in "multi-module mode") must point to a directory that holds one subdirectory for each contained module, where the directory name must equal the module name.
To accommodate layouts where sources are not directly contained in the module directory, the option supports patterns where the token *
can be used to represent the module name in any part of the path such as in "./*/src/main/java/"
, which will find the module my.mod1
in ./my.mod1/src/main/java/module-info.java
etc.
JEP 261 does not mention any contraints on where in the pattern *
may occur, but apparently javac
doesn't like patterns starting with *
. This may or may not be intentional.
Slightly related, I might add that in a previous discussion I was informed that JEP 261 contains outdated information, but my question whether and where this specification would be maintained after the JEP was completed, produced no answer. The javac manual entry is not the place that gives sufficient details for options like --module-source-path
.