Separate compilation with modular JARs?

Alan Bateman Alan.Bateman at oracle.com
Wed Jun 6 02:47:09 PDT 2012


On 06/06/2012 00:56, 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?
There are a couple of things here.

One is that Jon hasn't pushed the javac changes to support exports yet, 
I expect he will soon. Secondly, we don't have the runtime changes for 
module path in the runtime yet so you can't run with -mp or -modulepath 
yet. Thirdly, the resolver diagnostics need work so that we get good 
diagnostic messages at compilation or install time (or any time that the 
resolver is run). In the mean-time you need to get JIGSAW_TRACE to see 
what the resolver is going.

On using classpath vs. modulepath with separate compilations then I'll 
defer to Jon as there may be a javac issue there.

-Alan.













More information about the jigsaw-dev mailing list