Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. module module-a {
  2. exports com.mod-a;
  3. }
  4.  
  5. module module-c {
  6. requires module-a;
  7. provides com.mod-a.Service with com.mod-c.ServiceImpl;
  8. }
  9.  
  10. module module-b {
  11. required module-a;
  12. requires java.management;
  13. requires slf4j.api;
  14. uses com.mod-a.Service;
  15. }
  16.  
  17. ModuleFinder finder = ModuleFinder.of(moduleCPath);
  18. ModuleLayer parent = ModuleLayer.boot();
  19. Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("module-c"));
  20. ClassLoader scl = ClassLoader.getSystemClassLoader();
  21. ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
  22. //the following line prints "module-c"
  23. layer.modules().stream().map(Module::getName).forEach(System.out::println);
  24.  
  25. Iterable<Service> it = ServiceLoader.load(Service.class);
  26. System.out.println("LINE 1");
  27. for (Service service : it) {
  28. System.out.println("Service was called");
  29. service.doIt();
  30. }
  31. System.out.println("LINE 2");
  32.  
  33. LINE 1
  34. LINE 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement