Skip to content

Commit 82c195f

Browse files
committed
Java: write relative path for jvm.dir if possible
This relies on the scijava.app.directory property being set.
1 parent 66f70f4 commit 82c195f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/scijava/launcher/Java.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ public static void upgrade(BiConsumer<String, Double> subscriber)
325325
String configFileValue = System.getProperty("scijava.app.config-file");
326326
if (configFileValue != null && !configFileValue.isEmpty()) {
327327
File configFile = new File(configFileValue);
328+
String appDirValue = System.getProperty("scijava.app.directory");
329+
if (appDirValue != null) {
330+
Path appDirPath = Paths.get(appDirValue).normalize().toAbsolutePath();
331+
// If possible, use a path relative to the application directory.
332+
// This improves portability if the application gets moved
333+
// elsewhere, and/or accessed from multiple operating systems.
334+
try {
335+
newJavaPath = appDirPath.relativize(newJavaPath);
336+
}
337+
catch (IllegalArgumentException exc) {
338+
Log.debug(exc);
339+
}
340+
}
328341
Config.update(configFile, "jvm.dir", newJavaPath.toString());
329342
}
330343
}

0 commit comments

Comments
 (0)