Compiling classes for multi-release JAR with module-info.java
Paul Sandoz
paul.sandoz at oracle.com
Sun Feb 12 02:09:33 UTC 2017
It’s also possible to do this:
javac --source-path=src/main/java9 --source-path=src/main/java -implicit:none -d target/classes-java9 --release 9 $(find src/main/java9 -name "*.java”)
but that approach is fragile (it assumes the implicitly referenced source can be processed for release 8 and 9).
Separately compiling the module descriptor source is likely a better approach.
Paul.
> On 11 Feb 2017, at 09:40, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> On 10/02/2017 23:06, Gunnar Morling wrote:
>
>> :
>>
>> If I don't have a module descriptor things work fine:
>>
>> javac --source-path=src/main/java -d target/classes --release 8
>> $(find src/main/java -name "*.java")
>> javac --source-path=src/main/java9 -cp target/classes -d
>> target/classes-java9 --release 9 $(find src/main/java9 -name "*.java")
>> jar --create --file mr.jar -C target/classes . --release 9 -C
>> target/classes-java9 .
>>
>> Specifically, the second javac call picks up the (shared) class file
>> for "Version" from the classpath by pointing to the output directory
>> of the first compilation.
>>
>> Things fail when adding a module descriptor:
>>
>> --- src/main/java9/module-info.java
>> module com.example {
>> }
>> ---
> It is complicated but I think the reason you are running into issues is because the second javac command is essentially compiling a module with references to types on the class path.
>
> If you move the module-info.java to the top-level directory directory then I would expect this should work:
>
> javac --release 8 -d target/classes src/main/java/com/example/A.java src/main/java/com/example/Version.java
> javac -d target/classes src/main/java/module-info.java
> javac -d target/classes-java9 -cp target/classes src/main/java9/com/example/A.java
> jar --create --file mr.jar -C target/classes . --release 9 -C target/classes-java9 .
>
> Jon might have other suggestions.
>
> -Alan
More information about the jigsaw-dev
mailing list