-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
library(rJava) fails on Mac with JDK 8 or 10 #151
Comments
I also see this problem on R v3.4.3 and R v3.5.0 on macOS 10.13.5 and MacOS 10.11.6 (on an older machine) with both JDK 8u171 and JDK 10.0.1. The problem appeared with rJava 0.9-10. I have tested rJava 0.9-9 with R v3.3.3 on macOS 10.13.5 and MacOS 10.11.6 with both JDK 8u171 and JDK 10.0.1 and there is no problem. The message I get is:
So it looks like it wants JDK 9. I have never had JDK 9 installed on either machine and it is only available from Oracle archives with a recommendation not to use it. |
Have you reconfigured R to match you JDK? See R docs (c.f. |
Simon, Thanks you for following up. You write:
Yes. I did that:
Just a warning. This did not fix the issue. Do I need to do this and then reinstall rJava?
I tried javaconf and a number of other workarounds that I found on the web. Nothing seemed to work. I can load rJava running R in a terminal and in RStudio but not in the R GUI app or R-AnalyticFlow. That is not much use to me as most of my work is now in R-AnalyticFlow which fails to load rJava. I have 'downgraded" to R 3.3.3 and rJava 0.9-9. With >= R 3.4.x we get rJava 0.9-10 and that leads to the problem. my impression is that the issue is with rJava 0.9-10 as this failed to load with no change to the JDK giving the same error message. The downgrade is not ideal but it gives me my workflows back. |
@s-u, thank you for your feedback. For years
But anyway I tried
And I also find that
So here's the summary of what I've tried. All uses R-3.5.0 on macOS 10.13.5 and JDK 10.
So I can say:
|
It is perhaps inevitable given the complication and brittleness of many systems that I have a different experience from @r-suzuki. I find no issues with rJava 0.9-9 on any recent version of R in the Terminal, R GUI, RStudio, or R AnalyticFlow. Problems arise with rJava 0.9.10 in R GUI and R AnalyticFlow. |
@s-u, finally I have found the source of the problem. On Mac When calling rJava via JRI, there was no problem with 0.9-9. However this commit (90897df) may have changed the behavior. Setting For R GUI users it will be good if rJava can work without |
I updated the comment above to include |
Just to confirm ... that does do the trick in R AnalyticFlow. Many thanks for the excellent support. |
@r-suzuki this has nothing to do with Unless you re-compile rJava against your Java and fix the paths it will only work via the R script, not otherwise - this is due to the binaries that Oracle is supplying. The gory details: Unlike Apple, Oracle supplies Java binaries that don't work via jni, because they don't include the path to the Java installation in If you don't use the
Unfortunately this is an issue created by Oracle and no one else can fix it other than by modifying their binary to set the correct path (which is what Apple used to do). @markmyatt please don't set |
At the risk of going beyond the level of my ability ... no harm in appearing foolish ... Apple does provide a helper utility:
that, AFAIK, will reliably give the correct path to the default JDK. It can be used to find paths to different JDKs using filters for versions number and CPU architectures. I find it surprising that rJava and/or R GUI does not use this utility. A fallback to a hard coded path that may not exist does not seem sensible. This is just carping. I now have a working R-AnalyticFlow installation with current R and libraries running nicely and I am very happy about that. |
If you checked the code, you'd find out that it does ... That's exactly why I said don't set |
Thank you so much @s-u for details. I tried It would be great if it is automatically done in the binary installation process of rJava, but I'm not sure whether it's possible. Anyway thank you for your help! |
Using I think the process is a little tricky as the user needs to know the full pathname to I agree with @r-suzuki that it would be better if this could be done during package installation. The problem with this is that updating Java might need rJava to be reinstalled. |
No, unfortunately, it's not, because binaries are just files that are unpacked - there is no processing involved. The issue is really with Oracle - before they took over Apple was using a standard OS X framework structure so it worked fine regardless of the version. We had binaries that just worked - as you would expect on macOS. Unfortunately, Oracle doesn't seem to understand macOS at all so they ship their binaries in random locations with each update and without valid ID entry in binary so it's impossible to link against it. They break all the standard rules that Apple makes which is presumably why Apple stopped supporting Java altogether. |
I'd not like to apportion blame to just one side. Apple can be difficult and arbitrary at times. Did they really serve our best interests by taking their ball home WRT Java? This caused all sorts problems with other applications (e.g. SciLab). Sometimes I think they are not sure where to go with macOS. The good news here is that we have a working fix for the issue. |
IMHO, yes, they did, since Sun at the time had no solution at all. The issues were mostly related to the fact that Java is not really run-anywhere despite its promises - that's not Apple's fault. Apple actually had the only properly working Java on OS X. What's so frustrating is that if Oracle actually had anyone with a clue of OS X it's easy to fix - just create a standard framework which is a well-defined process and everything would work just fine. It's no rocket science - they could even just look at what Apple did and all would be well. It's also trivial to fix it, but as you said, you can't expect macOS users to do that themselves ... |
FWIW I think I'll just switch the CRAN machine to JDK 10 - then at least anyone with the currently supported Java will be fine. |
The old joke is that Java's "Write once. Run anywhere" promise is the usual case of "Write Once. Debug everywhere". That last post may have convinced me about Oracle. With (e.g) Java 8 the updates where on a major version number path so that if you had Java 8 and updated it it was still at:
I fear this may have changed. Your line above had I see a trend for apps to use an embedded JRE to avoid a lot of Java version issues. SciLab now does this in version 6 and later. Recent versions of R AnalyticFlow (RAF) do this. I think that is why the fix from @r-suzuki works but is RAF specific. |
@s-u Is there any standard way to use an alternative JRE other than the system default, when I want to use To launch a R CMD java -cp <ClassPath> <JavaClass> And R CMD javareconf -e JAVA_HOME=<JAVA_HOME> "java -cp <ClassPath> <JavaClass>" If I need to use R CMD java -cp <ClassPath>:<R LIBPATH>/rJava/java/boot/ <JavaClass> However changing JRE does not work in this situation with R CMD javareconf -e JAVA_HOME=<JAVA_HOME> "java -cp <ClassPath>:<R LIBPATH>/rJava/java/boot/ <JavaClass>" It fails to load
I needed to use It could be more of R's problem with Java. Thank you in advance for taking your time. |
JFYI this is the code used for testing: import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
public class JRIrJavaTest {
public static void main(String[] args)
{
Rengine engine = new Rengine(new String[]{"--no-save"}, false, null);
REXP result = engine.eval("try({"
+ "rJava::.jinit();"
+ "rJava::.jcall(\"java/lang/System\",\"S\",\"getProperty\",\"java.version\")"
+ "})");
System.out.println(result);
engine.end();
}
} Output example: |
Hi @r-suzuki , I recently run into the same rJava problem as you posted in this issue. After read your discussion with @markmyatt and @s-u I think I'm almost there but still can't
trying to compile and link a JNI program JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home and then
Before seeing your post I tried Do you have any idea how should I config this? Thanks! |
From your output you're using unsupported compilers so who knows what other issues you have. Please do not set |
Thanks Simon @s-u . I have
Are you saying I should downgrade it to older version of jdk, or it's in the wrong directory? |
Sorry being ambiguous, I meant C compiler (you have some clang in /opt), not Java |
After reinstalling JDK and rJava, The solution for me was closing Rstudio, running R CMD javareconf and then opening R in terminal, typing library(rJava), exiting the session, and then doing the same in Rstudio, at which point it finally worked. |
@david-bonin that is the only thing that worked for me as well! |
@david-bonin crazily, that also was what worked for me! Thanks. |
I'm not sure why people are surprised - exactly that is how its documented to work ... you have to make sure your R is configured with Java support and you have to re-run |
I never previously had problems, I only experienced this today while trying to install a package that has an rJava dependency. I ended up having to install JDK 11 and run |
You didn't need to do that for Apple Java, but since Apple dropped Java support and Oracle took over it was always necessary since Oracle doesn't play the the Apple rules. |
I tried running |
I had this problem but I was using JDK 13.0.1 and rJava was expecting 11.0.1 My rather stupid solution was to just rename the folder 'jdk-13.0.1.jdk' to 'jdk-11.0.1.jdk' and it's working perfectly fine so far |
@mgeard brilliant! I was spending ages on this problem - your solution was the only that worked for me :) |
@mgeard and @NateMietk , this also worked for me thanks a lot! |
Worked for me too! Thanks. |
renaming the folder worked for me too! Thanks! |
You save my life, @mgeard ! Rename works perfectly! |
I tried this morning, downloaded the updated |
After updating to the latest version or rJava (0.9-10),
library(rJava)
fails. It seems to search JDK 9 but it does not exist.It was working before updating rJava. And I don't have this issue on my Windows 7 machine (JDK 10 is installed).
System: R-3.5.0 (R GUI) on macOS 10.13.5
Error message (with JDK 8)
I also installed JDK 10 and got similar error:
Error message (with JDK 10)
I really appreciate it if you could check the problem.
The text was updated successfully, but these errors were encountered: