
Execute rJava code in a separate process with specific Java version
Source:R/java_scoped.R
with_rjava_env.RdRuns the provided function in a fresh R subprocess where rJava has not yet
been loaded. This allows you to enforce a specific Java version for rJava
operations without affecting the main R session or requiring a restart.
Arguments
- version
Java version specification. Accepts:
Major version (e.g.,
21,17): Downloads the latest release for that major version.Specific version (e.g.,
"21.0.9","11.0.29"): Downloads the exact version.SDKMAN identifier (e.g.,
"25.0.1-amzn","24.0.2-open"): Uses the SDKMAN backend automatically. When an identifier is detected, thedistributionandbackendarguments are ignored and derived from the identifier. Find available identifiers in theidentifiercolumn ofjava_list_available(backend = "sdkman").
- func
The function to execute in the subprocess.
- args
A list of arguments to pass to
func.- distribution
Character. The Java distribution to download. Defaults to "Corretto". Ignored if
versionis a SDKMAN identifier.- install
Logical. If
TRUE(default), attempts to download/install if missing. IfFALSE, returnsFALSEif the version is not found.- accept_system_java
Logical. If
TRUE(default), the function will scan the system for existing Java installations (usingJAVA_HOME,PATH, and OS-specific locations). If a system Java matching theversionandtyperequirements is found, it will be used. Set toFALSEto ignore system installations and strictly use anrJavaEnvmanaged version.- quiet
A
logicalvalue indicating whether to suppress messages. Can beTRUEorFALSE.- libpath
Optional character vector of library paths to use in the subprocess. Defaults to
.libPaths().