54 start("applib", "app1", "app1.Main");
55 start("applib", "app2", "app2.Main");
56 }
57
58 static void start(String appModulePath,
59 String appModuleName,
60 String appMainClass) throws Exception {
61
62 System.out.format("Starting %s/%s ...%n", appModuleName, appMainClass);
63
64 String[] dirs = appModulePath.split(File.pathSeparator);
65 Path[] paths = new Path[dirs.length];
66 int i = 0;
67 for (String dir: dirs) {
68 paths[i++] = Paths.get(dir);
69 }
70
71 ModuleFinder finder = ModuleFinder.of(paths);
72
73 Configuration cf = Layer.boot().configuration()
74 .resolveRequiresAndUses(finder,
75 ModuleFinder.of(),
76 Set.of(appModuleName));
77
78 System.out.println("Resolved");
79 cf.modules().stream()
80 .map(ResolvedModule::name)
81 .sorted()
82 .forEach(mn -> System.out.format(" %s%n", mn));
83
84 // reify the configuration as a Layer
85 ClassLoader scl = ClassLoader.getSystemClassLoader();
86 Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
87
88 // invoke application main method
89 ClassLoader loader = layer.findLoader(appModuleName);
90 Class<?> c = loader.loadClass(appMainClass);
91 Main.class.getModule().addReads(c.getModule());
92 Method mainMethod = c.getMethod("main", String[].class);
93
94 // set TCCL as that is the EE thing to do
|
54 start("applib", "app1", "app1.Main");
55 start("applib", "app2", "app2.Main");
56 }
57
58 static void start(String appModulePath,
59 String appModuleName,
60 String appMainClass) throws Exception {
61
62 System.out.format("Starting %s/%s ...%n", appModuleName, appMainClass);
63
64 String[] dirs = appModulePath.split(File.pathSeparator);
65 Path[] paths = new Path[dirs.length];
66 int i = 0;
67 for (String dir: dirs) {
68 paths[i++] = Paths.get(dir);
69 }
70
71 ModuleFinder finder = ModuleFinder.of(paths);
72
73 Configuration cf = Layer.boot().configuration()
74 .resolveAndBind(finder,
75 ModuleFinder.of(),
76 Set.of(appModuleName));
77
78 System.out.println("Resolved");
79 cf.modules().stream()
80 .map(ResolvedModule::name)
81 .sorted()
82 .forEach(mn -> System.out.format(" %s%n", mn));
83
84 // reify the configuration as a Layer
85 ClassLoader scl = ClassLoader.getSystemClassLoader();
86 Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
87
88 // invoke application main method
89 ClassLoader loader = layer.findLoader(appModuleName);
90 Class<?> c = loader.loadClass(appMainClass);
91 Main.class.getModule().addReads(c.getModule());
92 Method mainMethod = c.getMethod("main", String[].class);
93
94 // set TCCL as that is the EE thing to do
|