Search code examples
javararchlinuxrjava

How to set `Java headers gen.:` for R (to install `rJava`)


I am trying to install the package rJava in R on Arch Linux.

I got the error:

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.

Running sudo R CMD javareconf, I can see that Java headers gen.: is not set, but I have failed to figure out how to set it.

Here is the full java configuration seen by R (beside Java haders gen., the rest looks ok to me):

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

I do have javah in /usr/bin. But how do I "tell" this to R?


Solution

  • Thanks to @IvoVidovic's comment, I went to /usr/bin and inspected javah. It turned out that it was a symlink to a non-existent file. In fact, javah is missing from Arch Linux OpenJDK 10 (the file is not listed in the package contents).

    • Installing OpenJDK 9,
    • updating my JAVA_HOME with export JAVA_HOME=/usr/lib/jvm/java-9-openjdk,
    • setting OpenJDK 9 as my default jdk with sudo archlinux-java set java-9-openjdk,
    • and re-running sudo R CMD javareconf allowed R to find all the java files, including javah.

    I now have:

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

    and I could install rJava without any issue.

    Thanks again to @IvoVidovic who sent me in the right direction with his comment.