How to set JAVA_HOME and PATH in Windows 10 when loading rJava into R
Asked Answered
C

2

7

When loading rJava I get the following error message:

Error in get(Info[i, 1], envir = env) : lazy-load database 'C:/Users/dell_x/Documents/R/win-library/3.3/rJava/R/rJava.rdb' is corrupt

I have tried setting JAVA_HOME to the jre directory by doing all of these:

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java')
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_121')
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_121\\bin')
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_121\\bin\\server')

However, none of them seem to work. Before this, I was using the 32 bit version of Java and tried setting it to the 32 bit version (Program Files (x86)). The 32 bit version does not work either.

This is what I get when I query the PATH:

> Sys.getenv("PATH")
[1] "C:\\Program Files\\R\\R-3.3.0\\bin\\x64;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\WIDCOMM\\Bluetooth Software\\;C:\\Program Files\\WIDCOMM\\Bluetooth Software\\syswow64;C:\\Program Files (x86)\\Common Files\\Roxio Shared\\DLLShared\\;C:\\Program Files (x86)\\Common Files\\Roxio Shared\\10.0\\DLLShared\\;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files (x86)\\Calibre2\\;C:\\Program Files\\Git\\cmd;C:\\Users\\dell_x\\AppData\\Local\\Microsoft\\WindowsApps;"

I have the latest version of Java installed both in 32 and 64 bit. All I want is to be able to use open rJava in R. None of the paths I've mentioned earlier have worked (I still get an error when loading the Java library into R) and I can't find a specific jre folder or file to set the path to.

Countersignature answered 10/2, 2017 at 18:1 Comment(8)
"However none of them seem to work" ...work how? After trying to set JAVA_HOME via Sys.setenv, what's the output of Sys.getenv("JAVA_HOME")?Battat
Also, unless you're trying to point rJava at a particular, non-default JRE, you might want to permanently set JAVA_HOME in the control panel...Battat
I get the path I just set. However, I still can't load the rJava package into R. I get the same error message.Countersignature
...what error message?Battat
Error in get(Info[i, 1], envir = env) : lazy-load database 'C:/Users/dell_x/Documents/R/win-library/3.3/rJava/R/rJava.rdb' is corruptCountersignature
Possible duplicate of Unable to load rJava on RBattat
I guess what I cannot figure out is the path to the jre for this version of java. When I go to the Java folder in my program files I see a folder named "jre1.8.0_121". I've tried setting the path to this folder but it doesn't work. I've also tried setting it to the "bin" folder inside "jre1.8.0_121" and it doesn't work either. And I've also tried to set it to the "server" folder inside the "bin" folder with no luck. I can't find any specific file called jre so I don't know what is the jre path to get it to work... any suggestions?Countersignature
Try setting the path BEFORE you start R.Jordonjorey
C
2

This is a duplicate of both: Unable to load rJava on R and Problems loading rJava Package on Win7.

I needed to install the Java SE Development Kit for rJava to work (should have read the package's documents) and then set the JAVA_HOME path to the jre folder inside "jdk1.8.0_121". Finally restart RStudio and everything works fine (I can load the rJava package).

Sorry for the duplicate.

Countersignature answered 11/2, 2017 at 20:15 Comment(0)
N
0

The actual fix since this was the first question I came upon via Google myself:

  1. Make sure Java is installed (https://www.java.com/en/download/)
  2. Enter the following into your RStudio console (where the actual path might vary slightly depending on your version of Java): Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre-1.8\\'). It's the path to the folder where the "bin" folder is in your Java install.

This fixed my problem while trying to load xlsx package.

Nitroglycerin answered 28/9, 2023 at 17:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.