< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java
Print this page
@@ -249,14 +249,23 @@
if (taskHelper.getExistingImage() != null) {
postProcessOnly(taskHelper.getExistingImage());
return EXIT_OK;
}
+
+ if (options.modulePath.isEmpty()) {
+ // no --module-path specified - try to set $JAVA_HOME/jmods if that exists
+ Path jmods = getDefaultModulePath();
+ if (jmods != null) {
+ options.modulePath.add(jmods);
+ }
+
if (options.modulePath.isEmpty()) {
throw taskHelper.newBadArgs("err.modulepath.must.be.specified")
.showUsage(true);
}
+ }
JlinkConfiguration config = initJlinkConfig();
if (options.suggestProviders) {
suggestProviders(config, remaining);
} else {
@@ -364,15 +373,23 @@
} else {
roots.add(mod);
}
}
+ ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods, roots);
+ if (!finder.find("java.base").isPresent()) {
+ Path defModPath = getDefaultModulePath();
+ if (defModPath != null) {
+ options.modulePath.add(defModPath);
+ }
+ finder = newModuleFinder(options.modulePath, options.limitMods, roots);
+ }
+
return new JlinkConfiguration(options.output,
- options.modulePath,
roots,
- options.limitMods,
- options.endian);
+ options.endian,
+ finder);
}
private void createImage(JlinkConfiguration config) throws Exception {
if (options.output == null) {
throw taskHelper.newBadArgs("err.output.must.be.specified").showUsage(true);
@@ -396,26 +413,37 @@
//Ask the stack to proceed
stack.operate(imageProvider);
}
+ /**
+ * @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;
+ }
+
/*
* Returns a module finder of the given module path that limits
* the observable modules to those in the transitive closure of
* the modules specified in {@code limitMods} plus other modules
* specified in the {@code roots} set.
*/
public static ModuleFinder newModuleFinder(List<Path> paths,
Set<String> limitMods,
Set<String> roots)
{
+ if (Objects.requireNonNull(paths).isEmpty()) {
+ throw new IllegalArgumentException("Empty module path");
+ }
Path[] entries = paths.toArray(new Path[0]);
ModuleFinder finder = ModulePath.of(Runtime.version(), true, entries);
// if limitmods is specified then limit the universe
- if (!limitMods.isEmpty()) {
- finder = limitFinder(finder, limitMods, roots);
+ if (limitMods != null && !limitMods.isEmpty()) {
+ finder = limitFinder(finder, limitMods, Objects.requireNonNull(roots));
}
return finder;
}
private static Path toPathLocation(ResolvedModule m) {
< prev index next >