无法在 R/RStudio 中安装 rJava

Can't install rJava in R/RStudio

我正在尝试在我的 RStudio 上安装 'rJava' 包。但它给了我这个错误:

configure: error: one or more Java tools are missing.

*** JDK is incomplete! Please make sure you have a complete JDK. JRE is *not* sufficient.
configure: error: ./configure failed for jri
ERROR: configuration failed for package ‘rJava’
* removing ‘/Users/art/Library/R/3.4/library/rJava’
* restoring previous ‘/Users/art/Library/R/3.4/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

当我尝试在 R 上安装时,它给我:

checking whether JNI programs run... configure: error: Unable to run a simple JNI program. Make sure you have configured R with Java support (see R documentation) and check config.log for failure reason.
ERROR: configuration failed for package ‘rJava’
* removing ‘/Users/art/Library/R/3.4/library/rJava’
* restoring previous ‘/Users/art/Library/R/3.4/library/rJava’

一个旧的解决方案:sudo R CMD javareconf 曾经对我有用,但现在不行了。

这是它给出的:

Java interpreter : /usr/bin/java
Java version     : 1.8.0_252
Java home path   : /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/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
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/../include/darwin  -I/usr/local/include   -fPIC  -Wall -g -O2  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre
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 /Library/Frameworks/R.framework/Resources
Done.

java -version 给出:

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (Zulu 8.46.0.20-SA-macosx) (build 1.8.0_252-b14)
OpenJDK 64-Bit Server VM (Zulu 8.46.0.20-SA-macosx) (build 25.252-b14, mixed mode)

我的系统是 MacOS Mojave 10.14.6,谁能帮我解决这个问题?谢谢!

您的 JAVA_HOME 指向 JRE 文件夹。您需要将其设置为 JDK 文件夹。
您可以使用 /usr/libexec/java_home -v <version you want> 获取 JAVA_HOME 所需的路径。例如,要获取到 1.7 JDK 的路径,您可以 运行 /usr/libexec/java_home -v 1.7 并且它将 return 到 JDK 的路径。在您的 .profile.bash_profile 中只需添加 export JAVA_HOME=/usr/libexec/java_home -v <version> 就可以了。
如果要检查 JDK 安装,请执行 javac -version