From 3e299a2b8257b4154cd915fc970639e9d59ea78e Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Sun, 15 Feb 2026 01:28:08 +0600 Subject: [PATCH 1/5] Add exec flag to run commands with selected JVM Allow running arbitrary commands with JAVA_HOME and PATH set to the selected JVM. Signed-off-by: Mubashshir --- archlinux-java-run.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/archlinux-java-run.sh b/archlinux-java-run.sh index 10c0f6f..22aab76 100755 --- a/archlinux-java-run.sh +++ b/archlinux-java-run.sh @@ -36,8 +36,8 @@ function print_usage { USAGE: archlinux-java-run [-a|--min MIN] [-b|--max MAX] [-p|--package PKG] [-f|--feature FEATURE] [-h|--help] [-v|--verbose] - [-d|--dry-run] [-j|--java-home] - -- JAVA_ARGS + [-d|--dry-run] [-j|--java-home] [-e|--exec] + -- EOF } @@ -191,6 +191,23 @@ function generate_candiates { echo "$list" | xargs } +function env_switch_java_home() { + quote_args + + if [ $dryrun -eq 1 ]; then + echo "DRY-RUN - Generated command: env JAVA_HOME=/usr/lib/jvm/${ver} PATH=/usr/lib/jvm/${ver}/bin:\$PATH exec ${quoted_java_args[*]}" + exit 0 + fi + + if [ $verbose -eq 1 ]; then + echo_stderr "Executing command: JAVA_HOME=/usr/lib/jvm/${ver} PATH=/usr/lib/jvm/${ver}/bin:\$PATH exec ${quoted_java_args[*]}" + fi + + export JAVA_HOME="/usr/lib/jvm/${ver}" + export PATH="/usr/lib/jvm/${ver}/bin:$PATH" + exec "${java_args[@]}" +} + function test_javafx_support() { if [ "$major" -lt 9 ]; then testcmd="/usr/lib/jvm/${ver}/bin/java -jar ${JAVADIR}/archlinux-java-run/TestJavaFX.jar" @@ -243,6 +260,7 @@ for arg; do --min) args+=( -a ) ;; --max) args+=( -b ) ;; --help) args+=( -h ) ;; + --exec) args+=( -e ) ;; --package) args+=( -p ) ;; --feature) args+=( -f ) ;; --verbose) args+=( -v ) ;; @@ -256,6 +274,7 @@ features=( ) java_args=( ) quoted_java_args=( ) verbose=0 +exec=0 dryrun=0 javahome=0 args_parsed=0 @@ -307,6 +326,8 @@ while :; do ;; -j) javahome=1 ;; + -e) exec=1 + ;; --) args_parsed=1 ;; '') break @@ -353,6 +374,11 @@ for ver in $candidates; do exit 0 fi + if [ $exec -eq 1 ]; then + env_switch_java_home + exit 0 + fi + for ft in "${features[@]}"; do case "$ft" in javafx) From 06a6f405861669c8f5c911481bab591a1315f438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20La=C3=9F?= Date: Sat, 14 Feb 2026 20:48:07 +0100 Subject: [PATCH 2/5] Add example for new --exec flag to help output --- archlinux-java-run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archlinux-java-run.sh b/archlinux-java-run.sh index 22aab76..85ab3a3 100755 --- a/archlinux-java-run.sh +++ b/archlinux-java-run.sh @@ -86,6 +86,8 @@ EXAMPLES: && "\$JAVA_HOME"/bin/javac ... (launches javac from a JDK in version 11 or newer) + archlinux-java-run --min 25 --max 25 --exec -- bash -i + (launches interactive bash with Java 25 set as \$JAVA_HOME and as first element in \$PATH) EOF } From 0602143c8abc4e294335de97bfeaa3c6ac10a2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20La=C3=9F?= Date: Sat, 14 Feb 2026 20:50:29 +0100 Subject: [PATCH 3/5] Prepare v12 release --- CHANGES.md | 6 ++++++ archlinux-java-run.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 09c0338..e79f777 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changelog +## v12 +To be released + +* Support running arbitrary programs with $JAVA_HOME and $PATH set according + to requested Java version (#11) + ## v11 2025-01-03 diff --git a/archlinux-java-run.sh b/archlinux-java-run.sh index 85ab3a3..65da166 100755 --- a/archlinux-java-run.sh +++ b/archlinux-java-run.sh @@ -25,7 +25,7 @@ # This script uses `exec` on purpose to launch a suitable JRE before the end of # the script. # shellcheck disable=SC2093 -VERSION=11 +VERSION=12 JAVADIR=###JAVADIR### JAVAFX_MODULES=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web From a0637c72a47ae178ef8c0a593dc520c246848c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20La=C3=9F?= Date: Fri, 20 Feb 2026 20:30:29 +0100 Subject: [PATCH 4/5] Extend description of exec feature in help text While here, improve some of the naming to better describe what the new -e functionality actually does. --- archlinux-java-run.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/archlinux-java-run.sh b/archlinux-java-run.sh index 65da166..ce2cdd3 100755 --- a/archlinux-java-run.sh +++ b/archlinux-java-run.sh @@ -37,7 +37,7 @@ USAGE: archlinux-java-run [-a|--min MIN] [-b|--max MAX] [-p|--package PKG] [-f|--feature FEATURE] [-h|--help] [-v|--verbose] [-d|--dry-run] [-j|--java-home] [-e|--exec] - -- + -- EOF } @@ -58,7 +58,9 @@ this version, the one corresponding to the user's default JVM is used. By default, archlinux-java-run will execute a suitable version of java with the given JAVA_ARGS. When run with -j|--java-home, it just prints the location of a suitable java installation so that custom commands -can be run. +can be run. When run with -e|--exec, it will run EXEC_CMD in an +environment where \$JAVA_HOME and \$PATH is set so that the appropriate +Java version is used. EOF print_usage cat << EOF @@ -193,7 +195,7 @@ function generate_candiates { echo "$list" | xargs } -function env_switch_java_home() { +function exec_in_modified_env() { quote_args if [ $dryrun -eq 1 ]; then @@ -377,8 +379,7 @@ for ver in $candidates; do fi if [ $exec -eq 1 ]; then - env_switch_java_home - exit 0 + exec_in_modified_env fi for ft in "${features[@]}"; do From c47135e5fcfe0e4baa2712dab9745285058931e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20La=C3=9F?= Date: Fri, 20 Feb 2026 20:38:21 +0100 Subject: [PATCH 5/5] Update README, LICENSE, CHANGES --- CHANGES.md | 4 ++-- LICENSE | 2 +- README.md | 11 ++++++++--- archlinux-java-run.sh | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e79f777..707ea4c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,10 @@ # Changelog ## v12 -To be released +2026-02-20 * Support running arbitrary programs with $JAVA_HOME and $PATH set according - to requested Java version (#11) + to requested Java version (#11, #12) ## v11 2025-01-03 diff --git a/LICENSE b/LICENSE index 622cb2b..55e1269 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017, 2018, 2019, 2020, 2023, 2024 Michael Lass +Copyright (c) 2017–2026 Michael Lass Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b0a31d0..5393e12 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,16 @@ this version, the one corresponding to the user's default JVM is used. By default, archlinux-java-run will execute a suitable version of java with the given JAVA_ARGS. When run with -j|--java-home, it just prints the location of a suitable java installation so that custom commands -can be run. +can be run. When run with -e|--exec, it will run EXEC_CMD in an +environment where $JAVA_HOME and $PATH is set so that the appropriate +Java version is used. ## Usage ``` archlinux-java-run [-a|--min MIN] [-b|--max MAX] [-p|--package PKG] [-f|--feature FEATURE] [-h|--help] [-v|--verbose] - [-d|--dry-run] [-j|--java-home] - -- JAVA_ARGS + [-d|--dry-run] [-j|--java-home] [-e|--exec] + -- ``` ## Available features @@ -45,3 +47,6 @@ can be run. * Launch javac from a JDK in version 11 or newer: `JAVA_HOME=$(archlinux-java-run --min 11 --feature jdk --java-home) && "$JAVA_HOME"/bin/javac ...` + +* Launch interactive bash with Java 25 set as $JAVA_HOME and as first element in $PATH: + `archlinux-java-run --min 25 --max 25 --exec -- bash -i` diff --git a/archlinux-java-run.sh b/archlinux-java-run.sh index ce2cdd3..cd27580 100755 --- a/archlinux-java-run.sh +++ b/archlinux-java-run.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# (c) 2017, 2018, 2019, 2020, 2023, 2024 Michael Lass +# Copyright (c) 2017–2026 Michael Lass # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal