Run R from a tomcat-powered Java process on Amazon Linux

A memo because the contents were unexpectedly lost

Overview

See official for a description of the Java / R Interface itself https://www.rforge.net/JRI/

Java installation

Just install Java as usual and put it in the PATH, so omit it.

R installation

Yum is probably OK, but I wanted to include an older version so I made it myself.

wget https://cran.r-project.org/src/base/R-3/R-3.2.0.tar.gz
tar zxvf R-3.2.0.tar.gz
cd R-3.2.0
./configure --with-x=no && make && sudo make install

Include rJava package

sudo R CMD javareconf ##Automatically set Java environment information in R
sudo R ##R interactive shell launches
[R console] > install.packages('rJava') ##You will be asked if you want to install locally, so yes
[R console] > system.file("jri",package="rJava") ## (1)rJava location

Set environment variables

R RHOME ## (2)R location. The result is different from which R, but this is correct.
vi ~/.bash_profile
## bash_Appropriately added to profile
LD_LIBRARY_PATH=/usr/lib64/R/library/rJava/jri/:/usr/local/lib64/R/lib/ ## (1)
export LD_LIBRARY_PATH
R_HOME=/usr/local/lib64/R ## (2)
export R_HOME
source ~/.bash_profile

If you start the server the way you like, Java should recognize R correctly.

Recommended Posts

Run R from a tomcat-powered Java process on Amazon Linux
Install java 1.8.0 on Amazon linux2
Run a batch file from Java
Install Java8 with Yum on Amazon Linux
Try to build Java8 environment on Amazon Linux2
Run R from Java I want to run rJava
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
Downgrade Java on openSUSE Linux
Install rbenv on Amazon Linux
Run java applet on ubuntu
Run Java EE applications on CICS
Run React on a Docker container
Run node.js from android java (processing)
Access Teradata from a Java application
Run PureScript on a Docker container
Run tomcat shell script on java8
Run an external process in Java
How to run a GIF file from the Linux command line (Ubuntu)
Calling java from C ++ on Android NDK
[Java] Stepping on a JDK compiler bug
Try running a Kubernetes Job from Java
Build a Java development environment on Mac
Let's run Servlet on Amazon Corretto now
Deploy a Java web app on Heroku
How to install kafkacat on Amazon Linux2
If a person from Java learns PHP