Separate compilation with modular JARs?
Jesse Glick
jesse.glick at oracle.com
Tue Jun 5 16:56:42 PDT 2012
Unless I am missing something, I am finding it impossible to make Jigsaw's javac run sanely with modular JARs or unpacked class trees, i.e. without having to use jmod or
multi-module layout. Basically I just want to run javac exactly like you would with JDK 7 for a project with multiple physically separated components and acyclic
dependencies: with an explicit classpath for each component, and with module-info.java compiled to module-info.class with error checking, while enforcing module-based
accessibility (i.e. honoring 'exports' and similar). But it does not work:
mkdir -p modone/src/pkgone modone/bin modtwo/src/pkgtwo modtwo/bin
echo 'module modone at 1 {exports pkgone;}' > modone/src/module-info.java
echo 'package pkgone; public class C1 {}' > modone/src/pkgone/C1.java
echo 'module modtwo at 1 {requires modone at 1; class pkgtwo.C2;}' > modtwo/src/module-info.java
echo 'package pkgtwo; public class C2 extends pkgone.C1 {public static void main(String... args) {System.out.println(new C2());}}' > modtwo/src/pkgtwo/C2.java
javac -d modone/bin modone/src/module-info.java modone/src/pkgone/C1.java
javac -classpath modone/bin -d modtwo/bin modtwo/src/module-info.java modtwo/src/pkgtwo/C2.java
fails with:
error: Cannot resolve module dependencies using Jigsaw module resolver
modtwo@=1: Cannot resolve
1 error
with no further explanation. Same if I use -modulepath instead of -classpath. Even more worrisome, if I remove the 'requires' clause then compilation succeeds, whereas I
would expect classes from modone to be considered inaccessible in this case.
Also if I try to run the result:
java -modulepath modone/bin:modtwo/bin -m two
I get another error:
Error: -classpath and -cp cannot be used with -m
and -modulepath is not recognized by this command at all.
Is it planned for javac and java to work nicely with unpacked modules but just not yet implemented?
More information about the jigsaw-dev
mailing list