【问题标题】:R cannot find java home when using java JDK 1.8 - rJava won't work使用 java JDK 1.8 时 R 找不到 java home - rJava 不起作用
【发布时间】:2017-07-26 22:04:04
【问题描述】:

试图让 RJDBC 在 Rstudio 中工作,但我什么也做不了。我尝试重新安装 rJava 和堆栈溢出提供的其他一些解决方案,但没有任何效果。

首先,错误运行 library(RJDBC) 然后driver <- JDBC("com.amazon.redshift.jdbc42.Driver", "~/RedshiftJDBC42-1.2.1.1001.jar", identifier.quote="")`

给出错误

JavaVM: requested Java version ((null)) not available. Using Java at "" instead. JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib JavaVM FATAL: Failed to load the jvm library. Error in .jinit(classPath) : JNI_GetCreatedJavaVMs returned -1

阅读SO like this one上的一些解决方案

建议我需要运行sudo R CMD javareconf,它提供:

Java interpreter : /usr/bin/java
Java version     : 1.8.0_141
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_141.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/Users/rubinsjx/anaconda/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/../include/darwin -I/Users/rubinsjx/anaconda/include    -fPIC  -I/Users/rubinsjx/anaconda/include  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/rubinsjx/anaconda/lib/R/lib -arch x86_64 -L/Users/rubinsjx/anaconda/lib -lgfortran -L/Users/rubinsjx/anaconda -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/lib/server -ljvm -L/Users/rubinsjx/anaconda/lib/R/lib -lR -lintl -liconv -lc -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.8.0_141.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
LNGRDUM-4171620:etc rubinsjx$ Java library path: $(JAVA_HOME)/lib/server
-bash: JAVA_HOME: command not found
Error: Could not find or load main class library
LNGRDUM-4171620:etc rubinsjx$ JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
-bash: JAVA_HOME: command not found
-bash: JAVA_HOME: command not found
-bash: JNI: command not found 

在没有 -n 的情况下运行

Java interpreter : /usr/bin/java
Java version     : 1.8.0_141
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_141.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/Users/rubinsjx/anaconda/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/../include/darwin -I/Users/rubinsjx/anaconda/include    -fPIC  -I/Users/rubinsjx/anaconda/include  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/rubinsjx/anaconda/lib/R/lib -arch x86_64 -L/Users/rubinsjx/anaconda/lib -lgfortran -L/Users/rubinsjx/anaconda -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/lib/server -ljvm -L/Users/rubinsjx/anaconda/lib/R/lib -lR -lintl -liconv -lc -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.8.0_141.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 /Users/rubinsjx/anaconda/lib/R
Done.

一个奇怪的事情是我没有使用 anaconda 来运行 R。所以我不确定这是否会导致问题。

如果我再尝试重新安装 rJava

> install.packages("rJava", type = "source")
Installing package into ‘/Users/rubinsjx/Library/R/3.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-8.tar.gz'
Content type 'application/x-gzip' length 656615 bytes (641 KB)
==================================================
downloaded 641 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... clang
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 clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... 
rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
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 clang 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/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/System/Library/Frameworks/JavaVM.framework/Headers'
java libs   : '-framework JavaVM'
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
checking whether JNI programs can be compiled... 
configure: error: Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/Users/rubinsjx/Library/R/3.3/library/rJava’
* restoring previous ‘/Users/rubinsjx/Library/R/3.3/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/m2/qhhvggzd52gfff3xbvv7jlcwh_y23d/T/RtmpySEOWn/downloaded_packages’
> library(RJDBC)
Loading required package: DBI
Loading required package: rJava
> driver <- JDBC("com.amazon.redshift.jdbc42.Driver", "~/RedshiftJDBC42-1.2.1.1001.jar", identifier.quote="`")
JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
Error in .jinit(classPath) : JNI_GetCreatedJavaVMs returned -1
JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.

这真的让我发疯了。我只想将 R 连接到 Redshift 并过上我的生活!

【问题讨论】:

    标签: java r macos macos-sierra rjava


    【解决方案1】:

    放弃,从https://support.apple.com/kb/DL1572?locale=en_US 安装Java 1.6 根据这篇博文http://conjugateprior.org/2014/12/r-java8-osx/的建议 RJDBC 现在可以工作了。

    【讨论】:

      猜你喜欢
      • 2018-06-29
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 2016-06-09
      相关资源
      最近更新 更多