7

I am trying to install some packages (mailR) to be able to communicate errors and messages to my users by mail, and connecting to HIVE server via rJdbc but installing rJava dependency is getting convoluted more and more as steps are accomplished.

First error is asking for rJava package, so I tried installing rJava:

install.packages("rJava")

Installing package into ‘/home/joe/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-11.tar.gz'
Content type 'application/x-gzip' length 675188 bytes (659 KB)
==================================================
downloaded 659 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc -std=gnu99 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/lib/jvm/default-java/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : ''
java libs   : ''
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.

ERROR: configuration failed for package ‘rJava’
* removing ‘/home/jmvo/R/x86_64-pc-linux-gnu-library/3.6/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpkTvmz8/downloaded_packages’

So I followed the instructions as root and:

sudo R CMD javareconf

Java interpreter : /usr/lib/jvm/default-java/bin/java
Java version     : 11.0.3
Java home path   : /usr/lib/jvm/default-java
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

trying to compile and link a JNI program 
detected JNI cpp flags    : 
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-VAQCff/r-base-3.6.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: jni.h: No such file or directory
 #include <jni.h>
          ^~~~~~~
compilation terminated.
/usr/lib/R/etc/Makeconf:167: recipe for target 'conftest.o' failed
make: *** [conftest.o] Error 1
Unable to compile a JNI program


JAVA_HOME        : /usr/lib/jvm/default-java
Java library path: 
JNI cpp flags    : 
JNI linker flags : 
Updating Java configuration in /usr/lib/R
Done.

I´ve checked if I have Open JDK installed because many SO answers seems to be related with absence of JDK.

 java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

to be sure, tried installing again JDK with

sudo apt-get install openjdk-8-jdk                                                
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-8-jdk is already the newest version (8u212-b03-0ubuntu1.18.04.1).
0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.

Some other SO answers suggest installing rJava via apt-get this way

 sudo apt-get install r-cran-rjava

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-cran-rjava : Depends: r-api-3.4
E: Unable to correct problems, you have held broken packages.o 

But i`m using R 3.6, so going back is not an option. Changing to Oracle java is not an option. Many working apps are OpenJDK dependant.

No success so far. This is a never ending process. Tried many SO answers on the matter to no avail. I need rJava not only for mail but for many other processes like connecting to Hive , and so on... from R.

Thanks

Forge
  • 1,587
  • 1
  • 15
  • 36
  • Do you know if you have 32 bit or 64 R/Java, those also have to match to make this work I believe – Mike Jul 11 '19 at 13:28
  • 1
    Follow the answer here: https://stackoverflow.com/a/51267282/8386140 (I provide the link to the relevant answer rather than voting to close since the bounty prevents me from doing so). Long story short, the `r-cran-rjava` in the *Ubuntu repos* relies on `r-api-3.4`, so you use a PPA to get a version of `r-cran-java` that uses the API you need – duckmayr Jul 11 '19 at 15:22
  • You seem to have two different java versions installed: reconf indicates v11, while your apt command relates to v8. Perhaps the Java 11 being used by reconf does is JRE only or does not include the JNI header needed by reconf? – alan ocallaghan Jul 17 '19 at 13:29

0 Answers0