Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module module-a {
- exports com.mod-a;
- }
- module module-c {
- requires module-a;
- provides com.mod-a.Service with com.mod-c.ServiceImpl;
- }
- module module-b {
- required module-a;
- requires java.management;
- requires slf4j.api;
- uses com.mod-a.Service;
- }
- ModuleFinder finder = ModuleFinder.of(moduleCPath);
- ModuleLayer parent = ModuleLayer.boot();
- Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("module-c"));
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
- //the following line prints "module-c"
- layer.modules().stream().map(Module::getName).forEach(System.out::println);
- Iterable<Service> it = ServiceLoader.load(Service.class);
- System.out.println("LINE 1");
- for (Service service : it) {
- System.out.println("Service was called");
- service.doIt();
- }
- System.out.println("LINE 2");
- LINE 1
- LINE 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement