Separate compilation with modular JARs?
Paul Sandoz
paul.sandoz at oracle.com
Wed Jun 6 01:45:14 PDT 2012
Hi Jesse,
I can reproduce the same behavior. I had to install modone into a library so that i could compile modtwo separately.
Execution in exploded/unpacked mode is currently not implemented. It is planned. Alan has a patch that is currently bit rotting... i dunno if that patch also addresses the compilation case, which i think is important too.
Paul.
On Jun 6, 2012, at 1:56 AM, Jesse Glick wrote:
> 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