Compiling classes for multi-release JAR with module-info.java
Gunnar Morling
gunnar at hibernate.org
Mon Feb 13 17:49:05 UTC 2017
> 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.
Shouldn't this be supported, though?
I.e. is the observed behavior a bug and the contents from the given
classpath should actually be available for this compilation (this is
how I interpret http://openjdk.java.net/jeps/261)? Or is this behavior
intended and the given classpath is ignored in presence of a
module-info.java? In that case a warning about the classpath being
ignored would be nice.
What you suggest works for the given example, I'm not sure how it'd
look if the module-info.java had Java 9 specific references (e.g. a
provided service).
2017-02-11 18:40 GMT+01:00 Alan Bateman <Alan.Bateman at oracle.com>:
> 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