R and Java – JRI Using Netbeans

Setting up R-Java in Netbeans is pretty straight forward. For those who need a walkthough here are the steps.

  1. Download and install R (for this example version 2.12.2). install rJava package. 
  2.  Download and install Netbeans. 
  3. In Netbeans Create a new java project. we will call it RJava.
  4.  From the [R_HOME]>/library/rJava/jri/examples folder, copy the file rtest.java into the project.
  5. Create a library in NetBeans and add the following jars to the library. – JRI.jar, JRIEngine.jar, REngine.jar. These files are present in [R_HOME]/library/rJava/jri/. Here’s how the project looks like
  6. Minimize Netbeans. Add R_HOME variable (right click my computer-> properties-> Advanced ->Environment variables) R_HOME should point to the location where R is installed.
  7. edit the PATH variable and append the following (i) [R_HOME]libraryrJavajri and (ii) [R_HOME]bin

That’s it. Right click on rtest.java and click on ‘Run File’.

10 thoughts on “R and Java – JRI Using Netbeans

  • November 14, 2011 at 2:54 pm
    Permalink

    May i ask some question here. I am a beginner of R and Java. The JRI actually show that R and Java are able to interface each other, that mean R and Java is compatible? If i write some R code and i hope to run in Java, how it work? can u some me an simple example? like i write a R code which read the first line data of a file and then sum it and save in other file. I able to do this from R but how can i run the R code and show the result it java? how it interfacing?

    Reply
  • July 16, 2012 at 8:45 am
    Permalink

    I am getting the following error. Please help
    ————————————
    Creating Rengine (with arguments)
    Rengine created, waiting for R
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6c733cd8, pid=1488, tid=3220
    #
    # JRE version: 7.0_01-b08
    # Java VM: Java HotSpot(TM) Client VM (21.1-b02 mixed mode windows-x86 )
    # Problematic frame:
    # C [R.dll+0x33cd8]
    #
    # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
    #
    # An error report file with more information is saved as:
    # C:Program FilesRR-2.15.1libraryrJavajrihs_err_pid1488.log
    #
    # If you would like to submit a bug report, please visit:
    # http://bugreport.sun.com/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    Reply
  • February 11, 2013 at 10:23 pm
    Permalink

    Hi, I follow each step that is in your article, but i got this error:

    Cannot find JRI native library!
    Please make sure that the JRI native library is in a directory listed in java.library.path.

    java.lang.UnsatisfiedLinkError: C:Program FilesJavajdk1.7.0_04jrebinjri.dll: Can’t find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1846)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at org.rosuda.JRI.Rengine.(Rengine.java:19)
    at com.spontecorp.rjava.rtest.main(rtest.java:61)
    Java Result: 1

    I’m running on Windows 7 64 bits, JDK 1.7_04, Netbeans 7.2

    I read and apply every sujestion that I founded in google, but nothing, always the same error.

    By, the way ¿it is normal that rjava was installed in a different directory where R is installed?. I used the command install.packeges(“rjava”) and was installed automatically in a different directory, any way I setted this VM option; -Djava.library.path=C:UsersCasperDocumentsRwin-library2.15rJavajrix64.

    I´ll appreciate any help

    Reply
    • December 8, 2016 at 7:48 pm
      Permalink

      I have the same problem and I do not found any solution

      Reply
  • June 6, 2013 at 11:10 am
    Permalink

    Hi mithil,

    Thanks for the tutorial
    when i run rtest2 i have an interface containing this messeges: R version 2.15.2 (2012-10-26) — “Trick or Treat”
    Copyright (C) 2012 The R Foundation for Statistical Computing
    ISBN 3-900051-07-0
    Platform: i386-w64-mingw32/i386 (32-bit)

    R est un logiciel libre livré sans AUCUNE GARANTIE.
    Vous pouvez le redistribuer sous certaines conditions.
    Tapez ‘license()’ ou ‘licence()’ pour plus de détails.

    R est un projet collaboratif avec de nombreux contributeurs.
    Tapez ‘contributors()’ pour plus d’information et
    ‘citation()’ pour la façon de le citer dans les publications.

    Tapez ‘demo()’ pour des démonstrations, ‘help()’ pour l’aide
    en ligne ou ‘help.start()’ pour obtenir l’aide au format HTML.
    Tapez ‘q()’ pour quitter R.

    Letting go; use main loop from now on

    but i don’t know how to execute my rscript!!
    Can u give me an exemple how to run an rscript please??

    Reply
  • June 6, 2013 at 11:34 am
    Permalink

    when i run rthis test2 i have this message in netbeans output : Press to continue (time to attach the debugger if necessary)

    Creating Rengine (with arguments)
    Rengine created, waiting for R
    re-routing stdout/err into R console
    rBusy(0)
    >
    i don’t interstand what it mean can help me to resolve this and runing an Rscript via java please

    Reply
  • June 6, 2013 at 11:34 am
    Permalink

    when i run rthis test2 i have this message in netbeans output : Press to continue (time to attach the debugger if necessary)

    Creating Rengine (with arguments)
    Rengine created, waiting for R
    re-routing stdout/err into R console
    rBusy(0)
    >
    i don’t interstand what it mean can help me to resolve this and runing an Rscript via java please

    Reply
  • June 6, 2013 at 11:34 am
    Permalink

    when i run rthis test2 i have this message in netbeans output : Press to continue (time to attach the debugger if necessary)

    Creating Rengine (with arguments)
    Rengine created, waiting for R
    re-routing stdout/err into R console
    rBusy(0)
    >
    i don’t interstand what it mean can help me to resolve this and runing an Rscript via java please

    Reply
  • October 8, 2013 at 11:37 am
    Permalink

    i have now another error:
    Press to continue (time to attach the debugger if necessary)

    Creating Rengine (with arguments)
    Java Result: 10

    help plz

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.