rJava fails to install on server - java

I am trying to install rJava to conduct MaxEnt (Dismo package) on the servers of a super computer that run Linux. All the other packages have been successful, but rJava continues to give errors.
I have followed the answers from this thread including adding jre to my file path, using R CMD javareconf, and installing a new JDK and specifying that as the $JAVA_HOME. Unfortunately, I cannot use the apt-get function because of my role on the servers, although I believe this would be the best solution since it will correct my necessary file paths. However, perhaps I am missing something else that is causing the error.
This is the Java Version I am using:
- openjdk version "1.8.0_181"
- OpenJDK Runtime Environment (build 1.8.0_181-b13)
- OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
This is the error msg that is produced
checking whether ~/Core/java/1.8.0_121/bin/javah actually works... no
checking whether javah was replaced by javac -h... no
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 '/home/afila/R/x86_64-pc-linux-gnu-library/3.5/rJava'
The downloaded source packages are in
'/tmp/RtmpvYtNJY/downloaded_packages'

The issue I was having was indeed a permissions problem. Someone helped me resolve it by emulating the root system using proot. After that it was a matter of re-configuring the directory and R's access to it.
In Unix
mkdir ~/etc
cp -a $EBROOTR/lib64/R/etc/* ~/etc
proot -b
R CMD javareconf -e
In R
install.packages("rJava")
library(rJava)

Related

Problems with instalation of Rapidminer Studio (version 9.6) due to Java

I'm trying to install RapidMiner Studio and I'm having problems related with Java, running the installation file RapidMiner-Studio.sh in my terminal (OS Ubuntu 18.04). I think I have all the requirements to install RapidMiner. I found out I had to have Java 8 or OpenJDK 8, so I installed and configured as explained here. Also, from the same source's suggestions, I added this in the .sh file: --add-modules=java.xml.bind (after eval \"$JAVA\"). Like this:
if [ $# -gt 0 ]; then
eval \"$JAVA\" --add-modules=java.xml.bind $JVM_OPTIONS -cp \"${rmClasspath}\" com.rapidminer.launcher.GUILauncher \"$#\"
else
eval \"$JAVA\" --add-modules=java.xml.bind $JVM_OPTIONS -cp \"${rmClasspath}\" com.rapidminer.launcher.GUILauncher
fi
My OpenJDK version is this:
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
So, the errors I got from the installation file (after doing chmod +x RapidMiner-Studio.sh and ./RapidMiner-Studio.sh) are the following:
Error: Could not find or load main class com.rapidminer.launcher.JVMOptionBuilder
Unrecognized option: --add-modules=java.xml.bind
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
It's clear it doesn't recognize the added module java.xml.bind.
So without that added module in the .sh file, I removed it. And running, I got the following errors:
Error: Could not find or load main class com.rapidminer.launcher.JVMOptionBuilder
Error: Could not find or load main class com.rapidminer.launcher.GUILauncher
How can I solve this Java problem?
Thank you for your attention.
I'm answering my question. So, to solve this, I simply had to replace the original line rmClasspath="${RAPIDMINER_HOME}"/lib/* with rmClasspath=./lib/*. This wasn't about the Java, but really the shell script. I had defined RAPIDMINER_HOME previously and somehow itwasn't reconized in that if statement.

Trying to install rJava but error says JDK is incomplete

I'm using install.packages('rJava', type='source')to install rJava, but it presents with the following error:
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 ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
I just installed JDK8 so I'm not sure what's going on.
javac -version throws javac 1.8.0_231
java -version throws java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
This guy at R: rJava package install failing came up with a solution that I don't even understand since I'm new to this, but it has something to do with PATH and JAVA_HOMEand /jre apparently.
Looks like JAVA_HOME points to a JRE, not the JDK you want and need. Have a look at the top voted answer to "What should I set JAVA_HOME to on OS X". Also see https://developer.apple.com/library/archive/qa/qa1170/_index.html

Getting R to use newer versions of java

This question is related to this other question.
I am trying to use RNetLogo with R and get the following error.
nl.path <- "/Applications/NetLogo 5.1.0"
NLStart(nl.path)
Error in .jnew("nlcon/Preprocess") :
java.lang.UnsupportedClassVersionError: nlcon/Preprocess : Unsupported major.minor version 51.0
From what I understood in this other question, the problem is that R is using an old version of Java which is incompatible with RNetLogo.
I installed Java 8.0 hoping to solve the problem but my understanding is that, despite Java 8.0 being installed on my computer (Mac OS Maverick), R does not pick it up and keep trying to use old versions of Java.
So my question is : How can I get R to use Java 8.0 instead of any older version?
In the terminal console, I get
java -version :
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Thanks in advance for your help,
Seems like on Mac OS X you can have multiple Java at a one time.
Use below command on terminal to check how many JDK version you have.
/usr/libexec/java_home -V
You can follow below instruction to have correct Java Path setup:
How To Set $JAVA_HOME Environment Variable On Mac OS X
In nutshell do:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Unfortunately, none of these seem to help on a Mac. Windows and Linux solutions are not relevant because the files are in different places.
If you just update to Java 1.8 (Java 8 for Oracle) in the standard way as prompted by the Java preferences pain, you just get the Java Runtime Environment (JRE). If you run...
/usr/libexec/java_home -V
...it still shows only java 1.6, and...
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
...throws an error saying it can't find a version 1.8.
To get the Mac to even recognize a newer version of Java, it seems you must install JDK v.8 (not JRE). At that point, you can get the Mac to recognize that a new java virtual machine is available, and you can do the export command successfully. (Note that the new 1.8 JVM is in a DIFFERENT place--/Library/Java instead of /System/Library/Java for 1.6.). BUT, this still does no good for R.
I've tried putting the export JAVA_HOME... command into my .profile and my .bash_profile. Then sourcing both. Works fine, but has no effect on R AFAICT. I've launched R via the standard Mac R GUI, from RStudio, and from the terminal and it is only recognizing Java 1.6. So RNetLogo still does not work.
I will try to find RNetLogo 1.0-0 in the archive and test that. If it works, I suggest that 1.0-1 be rolled back until this Java problem is solved.
I use this line on windows :
options(java.home="C:/Program Files/Java/jre7/")
You probably have to change the 7 for an 8 and find the proper path on the mac.
This supposedly works (originally from this blog entry):
1) Download and install Apple’s Java version 1.6.
2) Reconfigure your Java installation by using sudo R CMD javareconf -n.
3) Reinstall rJava from source with: install.packages('rJava', type='source').
Please acknowledge Will Lowe at conjugateprior.org for the original post and solution.
Try linking libjvm.dylib to /usr/lib:
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/lib
-f flag is added to force overwriting existing file/link
EDIT: I don't know if anyone is still struggling with this, but with rJava 0.9-9, the 'partial fix' below no longer works. What does work, and completely, is the final solution offered here: https://github.com/s-u/rJava/issues/86
Copying from there, many thanks to Gregory R. Warnes:
uninstall existing rJava versions by running the following in the Terminal:
Rscript -e 'remove.packages("rJava")'
sudo Rscript -e 'remove.packages("rJava")'
add the following to /Users/<userid>/.bashrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)/jre'
(e.g., type > vim /Users/<userid>/.bashrc in the Terminal, then 'i', add the line above, then ':wq' to save and quit)
close and re-start all Terminal, R and RStudio windows
type the following in the Terminal window:
sudo ln -sf $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
in a new R session, re-install rJava from source:
install.packages("rJava", repos="http://rforge.net", type="source")
OLD 'PARTIAL FIX' BELOW:
Okay. I have been working on this problem all morning, and I have a partial fix.
I tried the solution suggested by Guilherme Kenji Chihaya above, but even after sudo R CMD javareconf -n and install.packages('rJava', type='source'), R insists on using Java 1.6 (and is happy to do so).
HOWEVER, R studio throws an error after re-installing rJava:
library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so
Reason: image not found
Error: package or namespace load failed for ‘rJava’
Googling this lead me to this post: http://andrewgoldstone.com/blog/2015/02/03/rjava/, with a working solution. Set the following in the Terminal:
alias r="DYLD_FALLBACK_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/server/: open -a r"
And start R from the Terminal. Then, magically, in R:
> library(rJava)
> .jinit()
> .jcall("java/lang/System", "S", "getProperty", "java.runtime.version")
[1] "1.8.0_11-b12"
However, this only works when starting R from the Terminal. I haven't been able to get R to automatically recognise the right "DYLD_FALLBACK_LIBRARY_PATH" in any way.
In Ubuntu there is a command alternatives that i use it for this purpose.
alternatives --install /usr/bin/java java /usr/java/jdk1.8*/jre/bin/java 200000
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8*/jre/bin/javaws 200000
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8*/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8*/bin/jar 200000
After alternatives install use the following command to change your version.
alternatives --config java and then select your newer java.
If this is not available you should first find out what where is your new java actually.
locate *jdk1.8*
Then find out which java you run as binary. which java this will returns the path of binary. this is the old java binary, So remove it and link new java binary in the same place. For example : ln -s /path/to/java1.8*/bin/java /usr/bin/java
In addtion you need to update your CLASS_PATH environment variable that is necessary for the VM.
for example:
export CLASS_PATH=/usr/java/jdk1.8*/jre/lib and you can add this line in your bashrc file to register this configuration.
In Debian-based installations R uses /etc/R/Makeconf settings for building libraries. One of the setting there is JAVA_HOME. Try setting the correct path there and reinstall the package.

Error while loading rJava

I get an error when I'd like to load rJava. JDK is installed. (I run R on a CentOS VM (cloudera demo vm cdh3u4))
> library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: package/namespace load failed for ‘rJava’
Is there something wrong with LD_LIBRARY_PATH settings? If yes, how can I fix that?
I need rJava running that to install rhdfs later.
Some more information (if needed):
[cloudera#localhost ~]$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
For Ubuntu, oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.
Create the file /etc/ld.so.conf.d/java.conf with the following entries:
/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
(Replace java-8-oracle with java-7-oracle or java-7-openjdk-amd64 depending on your java version)
Then:
sudo ldconfig
Restart RStudio and then install the rJava package.
Getting rJava to work depends heavily on your computers configuration. The following is working at least on a windows platform. You could try and check, if this will help you on your platform, too.
You have to use the same 32bit or 64bit version for both: R and JDK/JRE. A mixture of this will never work (at least for me).
If you use 64bit version make sure, that you do not set JAVA_HOME as a enviorment variable. If this variable is set, rJava will not work for whatever reason. You can check if your JAVA_HOME is set inside R with:
Sys.getenv("JAVA_HOME")
If you need to have JAVA_HOME set (e.g. you need it for maven or something else), you could deactivate it within your R-session with the following code before loading rJava:
if (Sys.getenv("JAVA_HOME")!="")
Sys.setenv(JAVA_HOME="")
library(rJava)
This should do the trick in most cases. Furthermore this will fix issue Using the rJava package on Win7 64 bit with R, too. I borrowed the idea of unsetting the enviorment variable from R: rJava package install failing.

Cannot load rJava because cannot load a shared library

I have been struggling to load the rJava package in R.
I get the following messages
> library(rJava)
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared library \
'C:/PROGRA~1/R/R-210~1.1/library/rJava/libs/rJava.dll':
LoadLibrary failure: The specified module could not be found.
Error : .onLoad failed in 'loadNamespace' for 'rJava'
Error: package/namespace load failed for 'rJava'
I have tried so many solutions that they are all bamboozeled in my head.
At some point I even got
> R Console: Rgui.exe - System Error The
> program can't start because
> MSVCR71.dll is is missing from your
> computer. Try reinstalling the program
> to fix this problem.
I made sure everything I could think of was on the path
> C:\Program Files\R\Rtools\bin;C:\Program Files\R\Rtools\perl\bin;
C:\Program Files\R\Rtools\MinGW\bin;%SystemRoot%\system32;
%SystemRoot%;%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\QuickTime\QTSystem\;
C:\Program Files\R\R-2.10.1\library\rJava\libs\;
C:\Program Files\R;C:\Program Files\Java\jre6\bin\client
What should I try next?
I am running R version 2.10.1 (2009-12-14) and I have also tried R version 2.10.1 Patched (2010-03-03 r51210). It is on a Windows machine running windows 7 enterprise
If you have read this threat and neither of the suggestions above has worked so far, then it might be worth trying one further:
Windows 7
R version 2.12.1 (2010-12-16) 64-bit
Java(TM) SE Runtime Environment (build 1.6.0_23-b05), Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
JAVA_HOME=C:\Program Files\Java\jre6\bin\
Path= ...;C:\Program Files\Java\jre6\bin\server\;C:\Program Files\R\R-2.12.1\bin\x64\
The thing that finally solved my problem was to explicitly add \server\ to the PATH variable.
For what it's worth, putting C:\Program Files\Java\jre6\bin\[server] in my PATH worked for me. It seems the rJava module could jot find jvm.dll there.
Here are the versions of R and Java that I'm using (on 64-bit Windows 7).
Java:
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
R:
R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)
System information:
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
I encountered this same problem. I was able to solve the issue with one line of code into the command window obtained from this website.
Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre7')
Note that I used this particular line because I was on a 64 bit system. See website for 32-bit example.
Following up on some of Dirk's sage advice:
Your path should probably say C:\Program Files\Java\jre6\bin\ (remove "client").
Your path should also have C:\Program Files\R\R-2.10.1\bin\. You don't need that explicit reference to the rJava libs. I would also then remove C:\Program Files\R from the path.
Lastly, confirm that Java is accessible by either going to your command prompt and typing java -version, or from within R by typing system("java -version").
If you install the SDK, then you will also want a system variable JAVA_HOME which in my case points to C:\Sun\SDK\.
After editing your post for readability / formatting it seems that you have no Java system in your path. I don't use the OS you're trying to use this on, but on mine rJava only works if I also install a Java Run-Time Environment or, better still, a Java SDK.
Note that the package clearly lists
SystemRequirements: java
and that the rJava site clearly states the following
Installation
First, make sure you have
JDK 1.4 or higher installed (some
platforms require hgher version see R
Wiki). On unix systems make sure that
R was configured with Java support. If
not, you can re-configure R by using R
CMD javareconf (you may have to
prepend sudo or run it as root
depending on your installation - see
R-ext manual A.2.2 for details). On
Windows Java is detected at run-time
from the registry.
rJava can be installed as any other R
package from CRAN using
install.packages('rJava'). See the
files section in the left menu for
development versions.
JRI is only compiled if supported,
i.e. if R was configured as a
framework or with --enable-R-shlib.
so I think we have a few smoking guns pointing the same way.
I had a similar error and had to do an additional fix: Setting the R path explicitly to ...bin\x64, and also being consistent in using x64 Java and R.

Categories

Resources