Run commands with a JDK
Use javm exec when a build, script, IDE launcher, or CI job needs a specific JDK but should not change the shell
that started it:
javm exec ./gradlew build # JDK from .java-version
javm exec mvn test
javm exec --jdk 21 java --version # explicit selector
javm exec --jdk temurin@21 ./gradlew build
What the command gets:
JAVA_HOMEset to the selected JDK, and itsbindirectory first inPATH.- The current directory, stdin, stdout, stderr, and the rest of the environment, unchanged.
- Its arguments exactly as written; javm does not parse anything after the command.
What stays the same:
- The current shell. Shell integration is not required.
Without --jdk, javm exec reads .java-version from the current directory. Native executables run without a
shell; on Windows, .cmd and .bat files run through COMSPEC.
If the selected JDK is not installed, javm exec fails with exit code 3; run javm install first. See
Exit codes.