我已经在github和stackoverflow上阅读了一段时间的这个问题。
但是,我似乎没有找到解决问题的正确方法。
这是我所做的事情的过程:
不久前,我开始使用Spark,我遇到了一个与Java相关的错误,根据这篇文章,我通过以下方式解决了:
sudo rm /usr/bin/java
sudo ln -s /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
今天,我尝试使用以下方法连接到我们的 Redshift 数据库:
redshift.drv <- JDBC('com.amazon.redshift.jdbc41.Driver',
'~/Amazon Redshift JDBC Driver/RedshiftJDBC41-1.1.10.1010.jar',
identifier.quote="'")
引发以下错误:
Error in .jfindClass(as.character(driverClass)[1]) : class not found
根据我运行的 github 上的答案:
$ R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.8.0_66
Java home path : /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Unable to locate an executable at "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/javac" (-1)
Java compiler : not functional
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
System Java on OS X
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags :
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -DPLATFORM_PKGTYPE='"mac.binary.mavericks"' -fPIC -Wall -mtune=core2 -g -O2 -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
^
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.
哪个 1st) 抛出这个conftest.c:1:10: fatal error: 'jni.h' file not found
错误,第 2 个)与 R 看到的不一致:
> J("java.lang.System")$getProperty("java.version")
[1] "1.6.0_65"
在这个阶段,我有一种"直觉",即我为能够使用 Spark 而运行的命令是不够的,因为很明显我没有一致的环境。
因此,我的问题是:
有谁知道此设置的修复方法?允许 R 查看 1.8.0_66 版本的东西(查找'jni.h'
文件等...
真的不需要重新做所有的Java安装,我只是想要一个干净,功能齐全的环境。
如果有任何帮助,此驱动程序可以完美运行:
prod.drv <- JDBC('com.microsoft.sqlserver.jdbc.SQLServerDriver',
'~/sqljdbc_4.0/enu/sqljdbc4.jar',
identifier.quote="'")
谢谢!
编辑:
我补充说:
setenv JAVA_HOME `/usr/libexec/java_home -v 1.8`
到我的.tcshrc
文件并运行:
R CMD javareconf JAVA_CPPFLAGS=/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/include/jni.h
(如果我没有明确传递JAVA_CPPFLAGS,它将无法找到它,获得与以前相同的错误)。
现在我收到以下错误:
Java interpreter : /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/bin/java
Java version : 1.8.0_73
Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home
Java compiler : /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/javac
Java headers gen.: /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/javah
Java archive tool: /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/jar
System Java on OS X
trying to compile and link a JNI program
detected JNI cpp flags: /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/include/jni.h
detected JNI linker flags : -framework JavaVM
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/include/jni.h -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -DPLATFORM_PKGTYPE='"mac.binary.mavericks"' -fPIC -Wall -mtune=core2 -g -O2 -c conftest.c -o conftest.o
clang: error: cannot specify -o when generating multiple output files
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.
因此,任何帮助将不胜感激:)
我遇到了同样的问题
Error in .jfindClass(as.character(driverClass)[1]) : class not found
并且找不到让它工作的方法。我用RPostgreSQL库来解决它,使用这个答案:https://stackoverflow.com/a/30855566/1686839