< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java
Print this page
@@ -25,11 +25,13 @@
package jdk.tools.jlink.internal;
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
import java.nio.ByteOrder;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -174,11 +176,28 @@
this.output = output;
this.modulepaths = modulepaths;
this.modules = Objects.requireNonNull(modules);
this.limitmods = Objects.requireNonNull(limitmods);
this.endian = Objects.requireNonNull(endian);
- this.finder = moduleFinder();
+ ModuleFinder finder = moduleFinder(modulepaths, limitmods, modules);
+ if (! finder.find("java.base").isPresent()) {
+ Path sysPath = getDefaultModulePath();
+ if (sysPath != null) {
+ this.modulepaths.add(sysPath);
+ }
+ // if java.base is still not found, error will be thrown later!
+ finder = moduleFinder(modulepaths, limitmods, modules);
+ }
+ this.finder = finder;
+ }
+
+ /**
+ * @return the system module path or null
+ */
+ public static Path getDefaultModulePath() {
+ Path jmods = Paths.get(System.getProperty("java.home"), "jmods");
+ return Files.isDirectory(jmods)? jmods : null;
}
/**
* @return the modulepaths
*/
@@ -242,11 +261,12 @@
return Configuration.empty().resolve(finder,
ModuleFinder.of(),
modules);
}
- private ModuleFinder moduleFinder() {
+ private static ModuleFinder moduleFinder(List<Path> modulepaths,
+ Set<String> limitmods, Set<String> modules) {
Path[] entries = modulepaths.toArray(new Path[0]);
ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries);
if (!limitmods.isEmpty()) {
finder = JlinkTask.limitFinder(finder, limitmods, modules);
}
< prev index next >