diff --git a/doc/user_guide.adoc b/doc/user_guide.adoc index a4842555..f5075910 100644 --- a/doc/user_guide.adoc +++ b/doc/user_guide.adoc @@ -310,7 +310,10 @@ to parse the templates, with the following variables available: - jvmArgs - args -The values in the *args* and *jvmArgs* lists may contain the placeholder `{{BIN_DIR}}`, which stands for the _bin_ directory of your custom runtime image. +The values in the *args* and *jvmArgs* lists may contain the following placeholders: + +- `{{BIN_DIR}}` - the _bin_ directory of the custom runtime image +- `{{HOME_DIR}}` - user's home directory (`$HOME` on Unix-like systems, `%USERPROFILE%` on Windows) You can include the value of an environment variable in a JVM argument by enclosing the name of the environment variable between `{{` and `}}`. diff --git a/src/main/groovy/org/beryx/jlink/util/LaunchScriptGenerator.groovy b/src/main/groovy/org/beryx/jlink/util/LaunchScriptGenerator.groovy index 66f76336..aca77540 100644 --- a/src/main/groovy/org/beryx/jlink/util/LaunchScriptGenerator.groovy +++ b/src/main/groovy/org/beryx/jlink/util/LaunchScriptGenerator.groovy @@ -39,6 +39,7 @@ class LaunchScriptGenerator { 'unixScriptTemplate.txt', 'unixScriptTemplate.txt', '$DIR', + '$HOME', '\\$$1'), WINDOWS( '.bat', @@ -46,6 +47,7 @@ class LaunchScriptGenerator { 'windowsScriptTemplate.txt', 'windowsScriptTemplateJavaw.txt', '%~dp0', + '%USERPROFILE%', '%$1%') final String extension @@ -53,16 +55,19 @@ class LaunchScriptGenerator { final String defaultTemplate final String defaultTemplateNoConsole final String binDirPlaceholder + final String homeDirPlaceholder final String envVarReplacement Type(String extension, Function templateProvider, String defaultTemplate, String defaultTemplateNoConsole, - String binDirPlaceholder, String envVarReplacement) { + String binDirPlaceholder, String homeDirPlaceholder, + String envVarReplacement) { this.extension = extension this.templateProvider = templateProvider this.defaultTemplate = defaultTemplate this.defaultTemplateNoConsole = defaultTemplateNoConsole this.binDirPlaceholder = binDirPlaceholder + this.homeDirPlaceholder = homeDirPlaceholder this.envVarReplacement = envVarReplacement } } @@ -112,6 +117,7 @@ class LaunchScriptGenerator { adjusted = '"' + adjusted + '"' } adjusted = adjusted.replace('{{BIN_DIR}}', type.binDirPlaceholder) + adjusted = adjusted.replace('{{HOME_DIR}}', type.homeDirPlaceholder) adjusted = adjusted.replaceAll(/\{\{([\w.]+)}}/, type.envVarReplacement) return adjusted }