title: How to set environment variables for R to use in Tomcat on RedHat Linux (RHEL6)
body: <p>I'm trying to set up R and Tomcat on RHEL6 (6.4)</p>
  
  <p>I have installed R and can run it.  I have installed Tomcat 7 and can host files file.
  I have packaged an application as a WAR file and deployed it using tomcat.
  The application runs fine in all aspects until it uses any R component.</p>
  
  <p>This is where it crashes out with the following error as seen in catalina.out:</p>
  
  <pre><code>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.&lt;clinit&gt;(Rengine.java:19)
  </code></pre>
  
  <p>I do have rJava installed under R: install.packages("rJava")
  It installed fine and I have rJava inside the R's library folder.</p>
  
  <p>I have defined the following in /etc/profile:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>To my understanding, that should set JAVA_HOME, R_HOME, PATH, and LD_LIBRARY_PATH globally for all users on the server.  I know Tomcat runs under root and I can confirm that root was able to see all the above paths as set above via "<code>echo $JAVA_HOME</code>", "<code>echo $R_HOME</code>", "<code>echo $LD_LIBRARY_PATH</code>", "<code>echo $PATH</code>"</p>
  
  <p>So I'm not sure why it's complaining that it can't open those .so files.</p>
  
  <p>Also, when it crashes out, it shuts down Tomcat.</p>
  
  <p>Thanks!</p>