0

I on macOS 10.13.3 and I just update to java 10 and when I've tried to update R to it I just realize that I get two different outputs if I run R CMD javareconf with or without sudo. If I run with sudo it sticks to Java 9, but if I run without sudo it configures java 10.

Without sudo:

$ R CMD javareconf                                                                        
Java interpreter : /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/java
Java version     : 10
Java home path   : /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
Java compiler    : /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/jar
Non-system Java on macOS

trying to compile and link a JNI program
detected JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
/usr/local/opt/llvm/bin/clang  -I/usr/local/Cellar/r/3.4.4/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/include/darwin  -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include   -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c conftest.c -o conftest.o
/usr/local/opt/llvm/bin/clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/Cellar/r/3.4.4/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/lib/server -ljvm -L/usr/local/Cellar/r/3.4.4/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/local/Cellar/r/3.4.4/lib/R
override rw-r--r--  root/admin for /usr/local/Cellar/r/3.4.4/lib/R/etc/Makeconf? (y/n [n]) y
override rw-r--r--  root/admin for /usr/local/Cellar/r/3.4.4/lib/R/etc/ldpaths? (y/n [n]) y
Done.

With sudo:

$ sudo R CMD javareconf                                                                   
Java interpreter : /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java
Java version     : 9.0.4
Java home path   : /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
Java compiler    : /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/javac
Java headers gen.: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/javah
Java archive tool: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/jar
Non-system Java on macOS

trying to compile and link a JNI program
detected JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
/usr/local/opt/llvm/bin/clang  -I/usr/local/Cellar/r/3.4.4/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/include/darwin  -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include   -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c conftest.c -o conftest.o
/usr/local/opt/llvm/bin/clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/Cellar/r/3.4.4/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/lib/server -ljvm -L/usr/local/Cellar/r/3.4.4/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/local/Cellar/r/3.4.4/lib/R
Done.

The end result of this is: without sudo and in consequence with java 10, rJava doesn't build. With sudo and java 9, rJava build normally.

Does anyone know what is going on?

PS1/ I have set $JAVA_HOME to JAVA_HOME="$(/usr/libexec/java_home)" in my zsh and bash profile.

PS2/ just for the sake of having all the info in one place... when building rJava with Java 10 I get the following error:

warning: [options] bootstrap class path not set in conjunction with -source 6
warning: [options] source value 6 is obsolete and will be removed in a future release
warning: [options] target value 1.6 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 warnings
/usr/bin/javah -d . -classpath . org.rosuda.JRI.Rengine
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/javah" (-1)
make[2]: *** [org_rosuda_JRI_Rengine.h] Error 2
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Users/lpuerto/Library/R/3.x/library/rJava’
* restoring previous ‘/Users/lpuerto/Library/R/3.x/library/rJava’

The downloaded source packages are in
    ‘/private/var/folders/wf/41gjf2mx7m7fmvfd8dr22_5h0000gn/T/RtmpT2kJMY/downloaded_packages’
Warning message:
In install.packages("rJava", repos = "cloud.r-project.org") :
  installation of package ‘rJava’ had non-zero exit status

I've checked and there isn't a javah on /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/javah as in Java 9.

lpuerto
  • 191
  • 2
  • 13
  • Doesn't `sudo` tend to scrub envvars when running things are root or another user? Having it in *your* zsh/bash profiles does nothing, since those are not necessarily being sourced in sudo's other-user environment. – r2evans Mar 27 '18 at 17:29
  • I run sudo `java --version` and got version 10. – lpuerto Mar 27 '18 at 17:31
  • i just edit to mention that I'm on macOS. – lpuerto Mar 27 '18 at 17:39
  • *If I run with sudo it sticks to Java 9, but if I run with sudo it configures java 10* ... do you mean "without" on one of those? – r2evans Mar 27 '18 at 17:39
  • yes, sorry I just edited – lpuerto Mar 27 '18 at 17:41
  • Perhaps this will identify envvars that are changed: `diff -u – r2evans Mar 27 '18 at 17:44
  • I passed that and I got this https://gist.github.com/luisspuerto/337f74e88e7910e59023c7da747a647c Basically root doesn't have set a JAVA_HOME... – lpuerto Mar 27 '18 at 17:54
  • So ... sounds like you found the source of your problem. Perhaps you should be setting that in root's profile or the global profile? – r2evans Mar 27 '18 at 18:06
  • I don't think so... why root is picking java 9.0.4 instead of java 9.0.1, which is also in the system? – lpuerto Mar 27 '18 at 18:08
  • besides of the config problem with sudo or without sudo, seems that rJava doesn't like Java 10. – lpuerto Mar 27 '18 at 19:15
  • There are numerous posts (on SO, within the rJava issues page) that suggest explicitly setting `JAVA_HOME` resolved most if not all of the problems. I suggest you try setting a system-wide value for that. For instance, if you do `sudo -i`, then `export JAVA_HOME="..."`, and then `R CMD javareconf` (as root), does it work? – r2evans Mar 27 '18 at 19:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/167710/discussion-between-lpuerto-and-r2evans). – lpuerto Mar 28 '18 at 08:57
  • I've just written a short note on this and hope it is helpful: https://zhiyzuo.github.io/installation-rJava/ – Zhiya Apr 13 '18 at 05:09
  • @Zhiya thanks for the contribution, but the problem here was to use the new java 10. Java 8 works perfectly and Java 9 too. I see you are using jenv. I used it in the past but did't work well. I know some people advocate to use java 8 with R, but in my opinion java is something that need to be up to date for security reasons and have multiple java version isn't a solution. – lpuerto Apr 13 '18 at 13:06

2 Answers2

0

I solved by creating a symbolic link from /usr/bin/javah to that path with sudo ln -s /usr/bin/javah /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/javah.

Hope it works for you too.

blmayer
  • 259
  • 4
  • 12
  • I just check it and you are creating a kind of a loop... `/usr/bin/javah` is already pointing to `/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/javah`. If you create a symbolic link there pointing to `/usr/bin/javah` is probably going to get messy. – lpuerto Apr 11 '18 at 14:35
  • the problem got solved updating to last dev version of rJava. – lpuerto Apr 11 '18 at 14:40
0

As it was discussed on the R-SIG-mac list the problem is solved if you update to the last dev version of rJava.

install.packages('rJava', repos = 'http://rforge.net')
KenHBS
  • 5,620
  • 6
  • 30
  • 42
lpuerto
  • 191
  • 2
  • 13