No rJava class exception found

I'm just trying to get a simple example of accessing a custom Java class from R using rJava.

HelloWorld.java

class HelloWorld { public static void main(String[] args){ System.out.println("Hello World!"); } } 

Compiled .java for .class as such:

 javac HelloWorld.java 

R-code (run from the same directory as HelloWorld.java and HelloWorld.class.

 library(rJava) > .jinit() [1] 0 > .jnew("HelloWorld") Error in .jnew("HelloWorld") : java.lang.ClassNotFoundException 

Thanks for any pointers.

+1
source share
1 answer

Since you are using your own class, you need to tell rJava where to find these custom classes. One way to do this is to indicate the location of your classes when calling jinit.

 library(rJava) # Assuming HelloWorld is in the current working directory .jinit(".") .jnew("HelloWorld") 

I would recommend reading the help page for .jinit

+5
source

All Articles