使用java JDK 1.8时R找不到java home - rJava无效

时间:2017-07-26 22:04:05

标签: java r macos macos-sierra rjava

试图让RJDBC在Rstudio中工作,我无法得到任何工作。我已经尝试重新安装rJava和堆栈溢出提供的其他一些解决方案,但没有任何工作。

首先,错误运行l ibrary(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并过我的生活!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)