Resolution exception when service interface gets exposed via --add-exports
Gunnar Morling
gunnar at hibernate.org
Mon Nov 20 21:04:46 UTC 2017
Hi,
I'm having one module which defines a service interface but does not export
that interface's package. In another module I wish to create an
implementation of that service, which should be possible via --add-exports.
I can successfully compile that second module, but running it fails:
Error occurred during initialization of boot layer
j.l.m.ResolutionException: Module com.example.b does not read a module
that exports com.example.a
It seems as if the service binding happens before the --add-exports of the
java invocation is processed. Please see below for the steps to reproduce.
Is it a bug or am I trying to do something unsupported here?
Thanks,
--Gunnar
=====
mkdir -p sources/com.example.a/src/main/java/a/
mkdir -p sources/com.example.b/src/main/java/b/
cat > sources/com.example.a/src/main/java/a/Hello.java << EOF
package a;
public interface Hello {
void world();
}
EOF
cat > sources/com.example.a/src/main/java/module-info.java << EOF
module com.example.a {}
EOF
cat > sources/com.example.b/src/main/java/b/HelloImpl.java << EOF
package b;
public class HelloImpl implements a.Hello {
public void world() { System.out.println( "Hello"); }
public static void main(String... args) {
java.util.ServiceLoader.load( a.Hello.class ).findFirst().get()
.world();
}
}
EOF
cat > sources/com.example.b/src/main/java/module-info.java << EOF
module com.example.b {
requires com.example.a;
provides a.Hello with b.HelloImpl;
uses a.Hello;
}
EOF
cd sources/com.example.a && javac -g -d ../../modules/com.example.a $(find
src/main/java -name "*.java") && cd ../..
cd sources/com.example.b && javac -g --add-exports
com.example.a/a=com.example.b --module-path ../../modules -d
../../modules/com.example.b $(find src/main/java -name "*.java") && cd ../..
java --add-exports com.example.a/a=com.example.b --module-path modules -m
com.example.b/b.HelloImpl
More information about the jigsaw-dev
mailing list