R-Project:xlsx包安装失败(由于Java问题)

14

我试图安装xlsx软件包,但不幸的是,Java出了问题,我无法解决。

请查看以下输出内容以获取安装xlsx软件包时产生的输出结果。

以下是输出结果:


R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("xlsx")
Installing package into ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
also installing the dependencies ‘rJava’, ‘xlsxjars’

trying URL 'contrib/rJava_0.9-6.tar.gz'
Content type 'application/x-gzip' length 567515 bytes (554 Kb)
opened URL
==================================================
downloaded 554 Kb

trying URL 'contrib/xlsxjars_0.6.1.tar.gz'
Content type 'application/x-gzip' length 9477071 bytes (9.0 Mb)
opened URL
==================================================
downloaded 9.0 Mb

trying URL 'contrib/xlsx_0.5.7.tar.gz'
Content type 'application/x-gzip' length 312839 bytes (305 Kb)
opened URL
==================================================
downloaded 305 Kb

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -m64 -std=gnu99
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 gcc -m64 -std=gnu99 accepts -g... yes
checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -m64 -std=gnu99 -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... 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 gcc -m64 -std=gnu99 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 : '/bin/java'
archiver    : '/bin/jar'
compiler    : '/bin/javac'
header prep.: '/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works... 
Error: Could not find or load main class getsp
no
configure: error: Java interpreter '/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status
ERROR: dependency ‘rJava’ is not available for package ‘xlsxjars’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/xlsxjars’
Warning in install.packages :
  installation of package ‘xlsxjars’ had non-zero exit status
ERROR: dependencies ‘rJava’, ‘xlsxjars’ are not available for package ‘xlsx’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/xlsx’
Warning in install.packages :
  installation of package ‘xlsx’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/Rtmpj1UG8a/downloaded_packages’

Java 已安装:

输入 java -version 命令,将会产生以下输出:

java version "1.7.0_71"
OpenJDK Runtime Environment (fedora-2.5.3.0.fc20-x86_64 u71-b14)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
"

执行“sudo R CMD javareconf”会导致:

"
Java interpreter : /bin/java
Java version     : 1.7.0_71
Java home path   : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre
Java compiler    : /bin/javac
Java headers gen.: /bin/javah
Java archive tool: /bin/jar

trying to compile and link a JNI progam 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux -I/usr/local/include    -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic  -c conftest.c -o conftest.o
gcc -m64 -std=gnu99 -shared -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm -L/usr/lib64/R/lib -lR


JAVA_HOME        : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib64/R
Done.

然而,安装 install.packages('rJava') 会导致:

checking Java support in R... present:
interpreter : '/bin/java'
archiver    : '/bin/jar'
compiler    : '/bin/javac'
header prep.: '/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works... 
Error: Could not find or load main class getsp
no
configure: error: Java interpreter '/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/Rtmpnl17m7/downloaded_packages’

我不知道如何解决这个Java问题。我使用RStudio和Fedora工作。非常感谢您的帮助。

谢谢

Tamas


你的系统上安装了Java吗?java -version - cdeterman
是的,请看下面我更新的帖子。 - tamasp
4个回答

16
如果您已经安装了Java,请尝试从命令行重置R的Java配置。
sudo R CMD javareconf

然后再尝试仅安装rJava(你可以先重新启动RStudio)

install.packages('rJava')

如果这仍然无法解决您的问题,则错误显示R无法加载getsp。

checking whether Java run-time works... 
Error: Could not find or load main class getsp

首先要确认 getsp 可以访问。

locate getsp

输出可能包含多个项目,但您应该找到类似以下内容的东西:

/usr/share/R/share/java/getsp.class

然后我们希望让这个可访问,因此将其导出以便R可以找到它:

export CLASSPATH=/usr/share/R/share/java
在同一个窗口中,启动另一个 R 会话并尝试再次安装 rJava
另一件需要注意的事情是检查 JAVA_HOME 环境变量,并重新运行 javareconf
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre
export PATH=$PATH:$JAVA_HOME/bin
sudo R CMD javareconf

建议在rJava问题中取消设置CLASSPATH,因为它可能会导致其他问题。在尝试更改JAVA_HOME之前,最好这样做,并在仍无法解决问题的情况下重新设置。

编辑

考虑到这个问题已经保持“未回答”状态相当长一段时间,我认为我应该添加我的推荐,即使用readxl包,它不使用Java。它安装更容易,是tidyverse的一部分。对于那些尝试使用Excel文件的人,这只是一个一般性的建议。


仍然无法工作。请参见上面的完整细节。谢谢。 错误:找不到或加载主类getsp 否 配置:错误:Java解释器'/bin/java'无法工作 错误:包“rJava”的配置失败 *删除“/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava” 警告:安装包“rJava”时出现非零退出状态 - tamasp
尝试了上述方法,但仍然出现以下问题: 检查Java运行时是否正常... 错误:找不到或加载主类getsp 否 配置错误:Java解释器'/bin/java'无法工作 错误:包'rJava'的配置失败
  • 删除'/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava'
我应该将CLASSPATH信息导出到哪里?
- tamasp
在上面添加了JAVA_HOME后,还有一个进一步的想法。 - cdeterman
问题仍未解决:检查Java运行时是否正常工作... 错误:找不到或加载主要类getsp 否 配置:错误:Java解释器'/ bin / java'无法工作 错误:软件包'rJava'的配置失败
  • 删除'/ home / tamaspavlicek / R / x86_64-redhat-linux-gnu-library / 3.1 / rJava' 警告:安装软件包'rJava'时出现非零退出状态
- tamasp
顺便说一句,我注意到你提到你正在使用Rstudio。你是在RStudio中还是在命令行上尝试安装rJava?RStudio需要重新启动才能识别环境的任何更改。你也可以尝试在R中直接设置JAVA_HOME,使用Sys.setenv(JAVA_HOME="/usr/share/...")。如果所有其他方法都失败了,你可能应该提交rJava问题 - cdeterman
显示剩余2条评论

3

好的,我最终通过在我的主文件夹的.bashrc中添加“JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25.x86_64/jre/”来实现了它。

感谢您的帮助,cdeterman。

最好的Tamas


如果你认为我的答案是正确的(即设置JAVA_HOME),请接受它。否则,请接受你自己的答案,以便其他人知道问题已解决。 - cdeterman

2

这是Java的问题。我认为您的系统尚未安装Java。请检查是否已经安装了Java:

java -version

如果返回“可以在以下软件包中找到程序Java”,则还没有安装Java,因此请执行以下命令:
sudo apt-get install default-jre
sudo apt-get install default-jdk

然后尝试重新安装该软件包。

-1

这个解决方案对我来说完美地起作用了:

https://orajavasolutions.wordpress.com/2014/06/03/installing-and-loading-xlsx-package-in-r-with-ubuntu/

请不要使用仅链接的答案:链接会随时间而失效,然后答案就毫无价值了。相反,请在您的答案中提供重要和有用部分的简洁摘要以及链接。 - Richard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接