Skip to content

Commit

Permalink
Java: write relative path for jvm.dir if possible
Browse files Browse the repository at this point in the history
This relies on the scijava.app.directory property being set.
  • Loading branch information
ctrueden committed Nov 21, 2024
1 parent 66f70f4 commit 82c195f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/scijava/launcher/Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ public static void upgrade(BiConsumer<String, Double> subscriber)
String configFileValue = System.getProperty("scijava.app.config-file");
if (configFileValue != null && !configFileValue.isEmpty()) {
File configFile = new File(configFileValue);
String appDirValue = System.getProperty("scijava.app.directory");
if (appDirValue != null) {
Path appDirPath = Paths.get(appDirValue).normalize().toAbsolutePath();
// If possible, use a path relative to the application directory.
// This improves portability if the application gets moved
// elsewhere, and/or accessed from multiple operating systems.
try {
newJavaPath = appDirPath.relativize(newJavaPath);
}
catch (IllegalArgumentException exc) {
Log.debug(exc);
}
}
Config.update(configFile, "jvm.dir", newJavaPath.toString());
}
}
Expand Down

0 comments on commit 82c195f

Please sign in to comment.