Skip to content

Commit ad1e55d

Browse files
committed
Add a script that runs in an isolated R session to test which Java version rJava will pick up given the path to a Java JDK installation. This will require an appropirate R function within the core package code.
1 parent 0149065 commit ad1e55d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# java-ver-via-rJava-init.R
2+
args <- commandArgs(trailingOnly = TRUE)
3+
java_home <- args[1]
4+
5+
# Set the JAVA_HOME environment variable
6+
Sys.setenv(JAVA_HOME = java_home)
7+
8+
# Update PATH to include the Java bin directory
9+
old_path <- Sys.getenv("PATH")
10+
new_path <- file.path(java_home, "bin")
11+
Sys.setenv(PATH = paste(new_path, old_path, sep = .Platform$path.sep))
12+
13+
# Load rJava and initialize the JVM
14+
library(rJava)
15+
.jinit()
16+
17+
# Check and print the Java version
18+
java_version <- rJava::.jcall("java.lang.System", "S", "getProperty", "java.version")
19+
20+
# Print the Java version
21+
cat("Java version:", java_version, "\nAt path:", java_home, "\n")

0 commit comments

Comments
 (0)