4

I am trying to setup a Java project on a Windows computer that invokes R code using rJava/JRI. I have installed JDK 1.8, R 3.5.3 and rJava library in R on my computer. I have added the following to my Pathvariable: D:\Program Files\R\R-3.5.3\bin\x64; D:\Program Files\R\R-3.5.3\library\rJava\jri\x64. I have also configured the Build Path in Eclipse by adding the three JAR files from the jri folder as external JARs and by changing the native library to D:/Program Files/R/R-3.5.3/library/rJava/jri/x64. These are the same steps that I've recently done on another Windows computer and afterwards the R test script worked perfectly. However, on my current computer I keep getting the following message:

Please make sure that the JRI native library is in a directory listed in java.library.path.

java.lang.UnsatisfiedLinkError: D:\Program Files\R\R-3.5.3\library\rJava\jri\x64\jri.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
    at rtest.main(rtest.java:61)

Any idea what's going wrong? I would be really greatful for any help.

EDIT: Here is what my Build Path looks like:

Build Path

EDIT2: Additionally, I have now copied all .DLL files from D:\Program Files\R\R-3.5.3\bin\x64 together with jri.dll to D:\Program Files\Java\jdk1.8.0_201\bin as recommended here. Still no luck.

AnjaM
  • 2,941
  • 8
  • 39
  • 62
  • Are you using eclipse? In run configuration set Working directory the folder with dlls – Rodrigo Menezes Mar 14 '19 at 12:33
  • Possible duplicate of [Java R Interface (JRI) Setup](https://stackoverflow.com/questions/19100875/java-r-interface-jri-setup) – Rodrigo Menezes Mar 14 '19 at 12:45
  • Yes, I'm using Eclipse. How do I set the Working directory? – AnjaM Mar 14 '19 at 13:12
  • Have you tried setting `PATH` variable as in [this answer](https://stackoverflow.com/a/44481011/1602555) – Karol Dowbecki Mar 14 '19 at 13:21
  • @KarolDowbecki The `jri.dll` is located at `D:\Program Files\R\R-3.5.3\library\rJava\jri\x64` and this path is included in the `PATH` variable. – AnjaM Mar 14 '19 at 13:35
  • @RodrigoMenezes I have tried another option recommended in the question you cited (see EDIT 2) but I keep getting the same error message. So while this might be the same question, the answers don't help. – AnjaM Mar 14 '19 at 13:46

4 Answers4

3
Please try this one:
Run As -> Run Configuration -> Set Environment Variables ->New
Name : PATH
Value: C:\Program Files\R\R-3.6.1\bin\x64;C:\Users\[Username]\Documents\R\win-library\3.6\rJava\jri\x64;

enter image description here

Ganesh Giri
  • 1,135
  • 11
  • 18
1

Ok, I got it. After having done everything that is listed in the first post, I also copied all .DLL files from D:\Program Files\R\R-3.5.3\bin\x64 together with jri.dll from D:\Program Files\R\R-3.5.3\library\rJava\jri\x64 to D:\Program Files\Java\jre1.8.0_201\bin (in addition to the JDK folder). Now the test script works. Thanks to everyone who tried to help!

AnjaM
  • 2,941
  • 8
  • 39
  • 62
0

Try this:

  1. Right click on project > Java Build Path (here you can look your libraries and import libraries)
  2. Try do a clean and build
  3. Check your JDK
  4. If you have others eclipse installed on your computer look your file eclipse.ini and check than your JDK is correctly linked
T04435
  • 12,507
  • 5
  • 54
  • 54
  • I have inserted a screenshot of the Build Path for this project into my original question. Not sure what else I can add there. I have just tried to clean and rebuild, but it didn't change anything. What do you mean by checking my JDK? I have only one Eclipse installed on this computer. – AnjaM Mar 14 '19 at 13:20
  • If you use a framework for your enterprise or some application into eclipse you can be use another JDK tthan requeriments and look your compatibility for your version of eclipse and your currently JDK check your applications vs JDK(if you use ) and Eclipse version vs JDK – ALEJANDRO MARTÍN MARQUÉS Mar 18 '19 at 07:52
0

I resolved this after coming across this bug report: https://www.mail-archive.com/openjfx-dev@openjdk.java.net/msg22016.html "As previously mentioned, the above exception is not thrown on machines where the Visual C++ 2019 redistributable is installed."

I downloaded the MS Visual C++ redistributable for 2015-2019 and installed it on two different computers with diff combinations of offAdoptJDK, jre_8u_202, and jre_8u_265, and this resolved my issue.

I downloaded the redistributable from the link below: https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0

For Windows 10, I installed "x64: vc_redist.x64.exe" above and then my program ran successfully.