How to set environment variables for R for use in Tomcat on RedHat Linux (RHEL6)

I am trying to configure R and Tomcat on RHEL6 (6.4)

I installed R and can run it. I installed Tomcat 7 and can host file files. I packaged the application as a WAR file and deployed it using tomcat. The application works perfectly in all aspects, until it uses any component R.

Here it crashes with the following error, as shown in the catalina.out file:

Cannot find JRI native library! Please make sure that the JRI native library is in a directory listed in java.li brary.path. java.lang.UnsatisfiedLinkError: /usr/local/lib64/R-2.15.3/library/rJava/jri/libj ri.so: libR.so: cannot open shared object file: Too many levels of symbolic link s at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675) at java.lang.Runtime.loadLibrary0(Runtime.java:840) at java.lang.System.loadLibrary(System.java:1047) at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19) 

I have rJava installed under R: install.packages ("rJava") It is installed perfectly, and I have rJava inside the R library folder.

I defined the following in the / etc / profile file:

 export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre export R_HOME=/usr/local/lib64/R-2.15.3 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$R_HOME/bin export PATH export LD_LIBRARY_PATH=$R_HOME/lib/libR.so,$JAVA_HOME/lib/amd64/server/libjvm.so 

As I understand it, this should set JAVA_HOME, R_HOME, PATH and LD_LIBRARY_PATH globally for all users on the server. I know that Tomcat runs as root, and I can confirm that root was able to see all of the above paths as above through " echo $JAVA_HOME ", " echo $R_HOME ", " echo $LD_LIBRARY_PATH ", " echo $PATH "

Therefore, I am not sure why he complains that he cannot open these .so files.

Also, when it crashes, it disables Tomcat.

Thanks!

+4
source share
2 answers

I had the same problem when I used R libraries with tomcat. He could not find R_HOME.

The solution is to update the file that sets the path for tomcat, because tomcat sets its own variables. File "yourPathToTomcat / tomcat / bin / setclasspath.sh", open it and add "export R_HOME = yourPathToR" to the end (just like you added it to the Linux environment, for example: export R_HOME = / usr / lib / R), Then you can run the application and it will work. Hope this can help someone .: D

+2
source

To use R from Java, you will need to install a JRI. Fortunately, JRI is now part of rJava and is installed with it.

JRI will require its own shared library, which is already installed using rJava. To find the JRI installed using rJava, use

  system.file("jri",package="rJava") 

from R [command line]. The above command will give you the way. You can find

libjri.so

which is the shared library that the JRI is looking for. You can specify this path obtained above via JAVA_OPTS as

  -Djava.library.path=${path-retrieved-from-R} 

which will be passed to the JVM settings when initializing Tomcat.

If you use multiple libraries, then please match the java parameter of the library path accordingly.

+1
source

All Articles