error: unable to load installed packages just now - java

When I tried to run the R console in Eclipse, I got this error:
....Please make sure that R package 'rj' (1.1 or compatible) is installed...
So I tried to install it in the R console like this:
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")
and got this error:
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rj.gd', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rj.gd/libs/rj.gd.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
and I found that when installing rJava using: install.packages("rJava") gets a similar error:
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
When I run sudo R CMD javareconf,I got this output:
Java interpreter : /usr/bin/java
Java version : 1.7.0
Java home path : /usr/lib/jvm/java-7-oracle/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
NOTE: Your JVM has a bogus java.library.path system property!
Trying a heuristic via sun.boot.library.path to find jvm library...
Java library path: $(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/lib/amd64/server
JNI linker flags : -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/lib/amd64/server -ljvm
JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
Updating Java configuration in /etc/R
Done.
by the way,my configuration is:
Ubuntu 11.10 64bit
Eclipse 3.7
Oracle-1.7-jdk
R version 2.15.1

For Linux(Ubuntu) users: If you have 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 depending on your java version)
Then:
sudo ldconfig
Restart RStudio and then install the rJava package.
OR
Also an alternative method is to export LD_LIBRARY_PATH with the value of Java library path obtained from the command R CMD javareconf -e and run install.packages

I got similar issue and was able to resolve it by running
R CMD javareconf -e
Output of the R CMD javareconf -e
Java interpreter : /export/apps/jdk/JDK-1_6_0_27/jre/bin/java
Java version : 1.6.0_27
Java home path : /export/apps/jdk/JDK-1_6_0_27
Java compiler : /export/apps/jdk/JDK-1_6_0_27/bin/javac
Java headers gen.: /export/apps/jdk/JDK-1_6_0_27/bin/javah
Java archive tool: /export/apps/jdk/JDK-1_6_0_27/bin/jar
Java library path: /export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
JNI linker flags : -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64 -L/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm
JNI cpp flags : -I/export/apps/jdk/JDK-1_6_0_27/include -I/export/apps/jdk/JDK-1_6_0_27/include/linux
The following Java variables have been exported:
JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
Running: /bin/bash
After setting LD_LIBRARY_PATH to the same value as JAVA_LD_LIBRARY_PATH as shown in the output above. I was able to install rj.
export LD_LIBRARY_PATH=/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Run R and then install rj by
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")

I found the solution:
export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server
then
sudo R CMD javareconf
Note: The path (java-7-oracle) needs to be updated based on your Java installation.

I did the following and it worked for me:
export LD_LIBRARY_PATH=$JAVA_LD_LIBRARY_PATH
sudo R CMD javareconf
I had to restart R then as well.

Years later, I ended up on this question after searching for an error reported by R after I had unsuccessfully installed a package on that required shifting to Oracle's Java.
All I had to do to fix it was:
$ sudo R CMD javareconf

or just set the library in R?
I just ran this command in R:
Sys.setenv(JAVA_HOME='/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server')
(replace "/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server" with your Java library path which can be found running "sudo R CMD javareconf")
Might not be the most elegant solution - but it worked for me!

I did not had the jdk installed which I could fix with
sudo apt-get install jdk-*
After that i could run the sudo R CMD javareconf which always drew an error message before. Everything was set correctly and no manual tweeks where required, and after that package installation ran smootly in R (restart required).

When facing missing limjvm.so errors make sure that the correct ldpaths is picked up from the standard configuration in /etc/R versus the one in /usr/lib/R/etc.

This fixes the LD_LIBRARY_PATH problem for me (Linux, Debian 7.1.0, tc-shell, R version 3.0.2):
Add this line to .cshrc:
setenv LD_LIBRARY_PATH $JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server
Adding this command to ~/.login was not enough; the environment variable LD_LIBRARY_PATH was still not known in new xterms: echo $LD_LIBRARY_PATH : LD_LIBRARY_PATH: Undefined variable. (Why??)
Curiously, when starting R as superuser, there was no problem with finding libjvm.so .

I fixed this by just running R with sudo, and then running install.packages('rJava`).

None of the above worked for me, the only solution that installed rJava on Linux Ubuntu without any problems was to pass RScript command after installation of the base R:
$ sudo Rscript -e 'install.packages("rJava", repos = "http://cran.r-project.org/")'

Related

JAVA_HOME file is not working and I couldn't update Java to 1.8 on Amazon EC2

I have an Amazon EC2 t3.medium instance on Linux.
I am trying to run Apache ni-fi on this instance and I need java.
When I check the JAVA_HOME default:
$ echo$JAVA_HOME
-bash: echo/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.2.x86_64: No such file or directory
Then, I downloaded java 1.8 by the following comamnds on terminal:
$ sudo yum install java-1.8.0-openjdk.x86_64
$ sudo update-alternatives --config java
(I selected 2 for java 1.8)
To find the location of my java file, I run them:
$ file $(which java)
/usr/bin/java: symbolic link to `/etc/alternatives/java'
$ file /etc/alternatives/java
/etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java'
$ file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=1b1c0fd721197a04f9bfc9b0891f1bd83a5f49d5, not stripped
I guess it is working properly. Then, I change JAVA_HOME from 1.7 to 1.8 by writing these commands on terminal for both ec2-user and root:
[root#ip-178-32-11-247 ~]# export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64"
[root#ip-178-32-11-247 ~]# PATH=$JAVA_HOME/bin:$PATH
In advance, I have setup nifi on root. And in nifi-1.16.0 directory, I am trying to run this command:
[root#ip-178-32-11-247 nifi-1.16.0]# bin/nifi.sh start
The Error message is:
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64
NiFi home: /root/nifi-1.16.0
Bootstrap Config File: /root/nifi-1.16.0/conf/bootstrap.conf
bin/nifi.sh: line 401: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/bin/java: No such file or directory
I thought that java is working but JAVA_HOME couldn't setup properly but I couldn't solve that. What should I do at that point to solve the problem and start nifi?
I will be appreciated very much if you can help, I coludn't start my term project because of this error :(
The correct path for JAVA_HOME should be /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java
export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java"
But probably you don't need to export JAVA_HOME anyway. You should have a link in /usr/bin/. You can check this by doing the following:
[ssm-user#ip-172-31-85-243 bin]$ which java
/usr/bin/java
By default Apache Nifi is using the executable /usr/bin/java, so you don't need to export JAVA_HOME.

dyld: Library not loaded: #rpath/libjli.dylib , java image not found

This is strictly for Mac OS Catalina 10.15.4
Tried setting environment variables in nano $HOME/.zshenv
this is what the path looks like export JAVA_HOME=$HOME/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk
Tried deleting JDK and then installing again, no success
I enter java --version into Terminal and get the error.
Error:
dyld: Library not loaded: #rpath/libjli.dylib
Referenced from: /Users/darianjennings/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/bin/java
Reason: image not found
zsh: abort java --version
Had to remove jdk folder from disk using the following commands.
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java
From there I had to re-install the .dmg file from Oracle.
Now when I type 'java --version' in Terminal I get the version type etc.
Then when I type 'which java' it shows 'usr/bin/java'
Not sure if I need to change my path in .zsh environment but I am getting a different error in Appium now:
'An unknown server-side error occurred while processing the command. Original error: could not sign with default certificate. Original error spawn ENOTDIR'

"Unable to run a simple JNI program" error message when installing rJava on R 3.6 for ubuntu bionic beaver

I have the very common problem that rJava does not install correctly on Ubuntu.
This problem has been dsicussed in multiple places here, here, here, to name a few.
The basic problem is that on installing the rJava package, the following error message is produced
configure: error: Unable to run a simple JNI program. Make sure you have configured R with Java support (see R documentation) and check config.log for failure reason.
Warning in system(cmd) : error in running command
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/jonno/R/x86_64-pc-linux-gnu-library/3.6/rJava’
There are various closely related solutions to this problem. Most of them use sudo R CMD javareconf to configure Java for R (also a -e variant). Some suggest setting the JAVA_HOME path in the environment variables (others say not to). Others suggest uninstalling and re-installing R whilst others suggest installing rJava from cran. There are several who reccomend update alternatives. There are other variants of these solutions.
I have tried combinations of all of the above, and have got nowhere, so am clearly doing something wrong.
entering echo $JAVA_HOME returns
/usr/lib/jvm/java-11-openjdk-amd64
my etc/environment looks like this
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/$
MKL_THREADING_LAYER=GNU
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
When I run R CMD javaconf, it looks like this
Java interpreter : /usr/lib/jvm/java-11-openjdk-amd64/java
Java version : 11.0.4
Java home path : /usr/lib/jvm/java-11-openjdk-amd64
Java compiler : /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/lib/jvm/java-11-openjdk-amd64/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fpic -g -O2 -fdebug-prefix-map=/build/r-base-uuRxut/r-base-3.6.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-11-openjdk-amd64/lib/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-11-openjdk-amd64
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
What am I doing wrong and how do I get rJava to install properly?
EDIT:
having managed to successfully install rJava using sudo apt-get install r-cran-rjava I know get the following error
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
I've investigated with the original poster (we work at the same place) and the problem is that in OpenJDK11 they moved around some of the .so files that the JVM lives in, specifically libjvm.so which in the Ubuntu package is now in /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server/.
This means that even if you install the Ubuntu package for rJava with apt install r-cran-rjava it fails when you try to library(rJava).
The solution is to add /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server/ to your $LD_LIBRARY_PATH by adding:
export LD_LIBRARY_PATH=/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server:$LD_LIBRARY_PATH
to the end of your ~/.bashrc and starting a new shell (or source ~/.bashrc).
This is something we had to fix for our central installs of OpenJDK e.g. here: https://github.com/UCL-RITS/rcps-buildscripts/blob/master/adoptopenjdk-11.0.3_install.sh#L46
If you want to make this work with Rstudio launched from Gnome, you need to add that directory to ldconfig.
As root (or with sudo) create a file in /etc/ld.so.conf.d/ which you should call something with a .conf extension e.g. java.conf which contains the line:
/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server
And then as root run
ldconfig -v
This should add the directory to the locations that executables launched through GNOME search for. This particular part of the problem (GNOME ignoring settings in bashrc) has been a problem in Ubuntu since at least 9.04 (https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/366728/).

Unable to install rJava in R 3.0 in Ubuntu 13.04

I am not able to call rJava package in R 3.0. I got the following message
Error: package ‘rJava’ was built before R 3.0.0: please re-install it
I am getting error when I tried to re-install rJava package. I have provided the output of R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_21
Java home path : /usr/lib/jvm/java-7-openjdk-i386/jre
Java compiler : /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/jar
trying to compile and link a JNI progam
detected JNI cpp flags :
detected JNI linker flags :
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -O2 -pipe -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I am using Ubuntu 13.04. I also tried apt-get install r-cran-rjava which is not helping to solve the issue. Regarding jni.h there were some solution here. But, not sure how can I use the solution here.
I ran into the exact same issue. My solution was to install the openjdk-7-* via
sudo apt-get install openjdk-7-*
Followed that with
sudo R CMD javareconf
and I was then able to install rJava in R via install.packages("rJava").
While perhaps not the most elegant solution it appears to have solved my problems with getting rJava to work.
For those getting the error:
error: unable to load shared object '/some/dir/rJava/libs/rJava.so': libjvm.so:
cannot open shared object file: No such file or directory
I solved the error locating the library in the system and linking them to /usr/lib:
$sudo updatedb
$locate libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Installing rJava from the distribution packages as proposed in this askUbuntu answer also works:
sudo apt-get install r-cran-rjava
NOTE: tried from a Debian system.
I was also facing same error which was on RHEL8.1 & i resolved it as follows:
yum --enablerepo=* install java-1.8*
later i ran same command which was giving me error logs of R server.
R CMD javareconf
which turns into following output.

Apache Ant 1.8 on CentOS

I am trying to get apache ant 1.8 to work under CentOS. First, I had this error.
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
Then I set the following variables according to this link:
Ant: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
It's not CentOS, but I did verify the paths exist except JAVA_HOME, so I set it according to this site:
https://serverfault.com/questions/50883/what-is-the-value-of-java-home-for-centos
Now I am getting the same error I did the first time. It does not matter which ant rule I use, I still get the same error.
[alpha:~]
[bullshark]% export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/
[alpha:~]
[bullshark]% export ANT_HOME=/usr/share/ant/
[alpha:~]
[bullshark]% export PATH=$PATH:$ANT_HOME/bin
[alpha:~]
[bullshark]% cd JRobo
[alpha:JRobo] on master
[bullshark]% ant clean-and-fat-jar
Picked up _JAVA_OPTIONS: -Xmx64m
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
[alpha:JRobo] on master
[bullshark]% cat /etc/redhat-release
CentOS release 6.3 (Final)
[alpha:JRobo] on master
[bullshark]%
You can clone him on CentOS if you want to try:
https://github.com/BullShark/JRobo
For Apache Ant 1.8 on CentOS:
http://www.jpackage.org/browser/rpm.php?jppversion=6.0&id=11867
For a package or manually:
https://ant.apache.org/bindownload.cgi?Preferred=ftp://apache.mirrors.pair.com/
Here are the steps required to get ant 1.8 installed on CentOS:
Download http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.4-bin.tar.gz
Copy the tarball to your CentOS home folder (if it's not already there)
tar xvzf apache-ant-1.8.4-bin.tar.gz
sudo mv apache-ant-1.8.4 /opt/ant
Set ANT_HOME=/opt/ant
Add ‘export ANT_HOME=/opt/ant’ to /etc/profile
To verify that it worked, run:
ant -version

Categories