rJava class not found exception

为君一笑 提交于 2019-12-11 05:09:31

问题


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

HelloWorld.java

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

compiled .java to .class as such:

javac HelloWorld.java

R code (ran from same directory as HelloWorld.java and HelloWorld.class.

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

Thank you for any pointers.


回答1:


Since you're using a custom class you need to tell rJava where to find these custom classes. One way to do this is to specify the location of your classes when you call jinit.

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

I would recommend reading the help page for .jinit



来源:https://stackoverflow.com/questions/11106061/rjava-class-not-found-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!