Tuesday, February 19, 2013

Link Java and R for modeling on x64 computer

Water research, sometimes, needs model development. Some researchers may be interested in self-designing a model. Java language may be a useful language for model development; however, statistical analysis tools and graphs are hardly included in it. R language is publicly developed with a lot of packages of statistical analysis and graphs included but simulation on R has low simulation speed. Thus, linkage between Java and R is suggested. Some like to link Java from R, others prefer calling R from Java. This part will introduce how to set up to work on Java using R tools. Many people have no problem of having Java-R on x32 computer but others could not link Java to R on x64 computer. Please see some screenshots on my x64 computer for setting relationships between Java and R. 

Download and install Java software
  1. Netbeans 7.2 at http://netbeans.org/
  1. JDK @ http://www.oracle.com/technetwork/java/javase/downloads/index.html
Install R software 
              1. Install R @ http://www.r-project.org/ 
              2. Install package rJava using load.packages('rJava') 
              3. Set up environment variables
    • Right-click: Computer-properties-advanced system setting-environment variables
  • Add PATH: C:\Program Files\R\R-2.15.1\bin\x64 (locate R.dll);C:\Users\ntntanh\Documents\R\win-library\2.15\rJava\jri (R library);C:\Users\ntntanh\Documents\R\win-library\2.15\rJava\jri\x64 (JRI library for x64);C:\Program Files\Java\jdk1.7.0_05\bin (for java virtual machine JVM);C:\Program Files\Java\jdk1.7.0_05\jre\bin\server (JVM) (Check paths on your computer!!!)
  • Open netbeans-right click on the project-properties-Run-

Add in VM Options: -Djava.library.path="C:\Users\ntntanh\Documents\R\win-library\2.15\rJava\jri\x64"

Then click OK

Add JRI libraries from C:\Users\ntntanh\Documents\R\win-library\2.15\rJava\jri 

Good luck!


  1. Thanks Tanh! I'm sure people will find this useful as these two different programs are used often!

  2. Good explanation. Some pictures and flowcharts will be good.