Benoît Thiébault
2014-Sep-26 11:55 UTC
[R] [rJava] RJavaClassLoader and system classloader
Hi everyone, I want to call a Java application from R and have encountered some problems with the way rJava deals with the system class loader. To run my application, I use the following R script:> library(rJava) > .jinit() > .jaddClassPath("myApp.jar") > rWrapper <- .jnew("org/test/RWrapper") > .jcall(rWrapper,"V","start")My Java application has a plugins loading mechanism that uses a specific PluginClassLoader to load plugins stored in additional JAR files (e.g. plugin.jar). This PluginClassLoader is programed so that it knows and loads the plugins JARs. As any Java classloader, it is a child of the system class loader. Finally, plugins not only use classes stored in their plugin.jar file, they also depend on classes contained in the main myApp.jar file (the Plugin interface is for example defined in the myApp.far) In a pure Java environment, myApp.jar is known from the system class loader (it is in the classpath) and thus the PluginClassLoader can load classes from the plugin (it knows both about the plugin.jar and the myApp.jar files) In the R context however, using the above script, its the RJavaClassLoader that knows about the myApp.jar file. The org.test.RWrapper class is instatiated by the RJavaClassLoader. The system class loader however does not know about myApp.jar anymore. Neither does the PluginClassLoader. So when the PluginClassLoader loads a plugin class, it can only load classes that are in the plugin.jar file and as soon as a class from the myApp.jar file is required by the plugin, it crashes with a java.lang.NoClassDefFoundError message. My question is: how can I force rJava to load the classpath in the system classloader and not only in the RJavaClassLoader? I cannot make the PluginClassLoader know the RJavaClassLoader as my application also has to run in a non-R environment. Thanks for your time, Kind regards, Ben
Mohan Radhakrishnan
2014-Sep-30 10:23 UTC
[R] [rJava] RJavaClassLoader and system classloader
Hi, You could ask the author or post an issue here .( https://github.com/s-u/rJava) I had faced a problem and I got a response from him. In my case I am streaming JVM data and this( http://www.openanalytics.eu/r-service-bus) may be a better idea. I haven't still tried this. Thanks, Mohan On Fri, Sep 26, 2014 at 5:25 PM, Beno?t Thi?bault <thiebault at artenum.com> wrote:> Hi everyone, > > I want to call a Java application from R and have encountered some > problems with the way rJava deals with the system class loader. > > To run my application, I use the following R script: > > > library(rJava) > > .jinit() > > .jaddClassPath("myApp.jar") > > rWrapper <- .jnew("org/test/RWrapper") > > .jcall(rWrapper,"V","start") > > My Java application has a plugins loading mechanism that uses a specific > PluginClassLoader to load plugins stored in additional JAR files (e.g. > plugin.jar). This PluginClassLoader is programed so that it knows and loads > the plugins JARs. As any Java classloader, it is a child of the system > class loader. > > Finally, plugins not only use classes stored in their plugin.jar file, > they also depend on classes contained in the main myApp.jar file (the > Plugin interface is for example defined in the myApp.far) > > In a pure Java environment, myApp.jar is known from the system class > loader (it is in the classpath) and thus the PluginClassLoader can load > classes from the plugin (it knows both about the plugin.jar and the > myApp.jar files) > > In the R context however, using the above script, its the RJavaClassLoader > that knows about the myApp.jar file. The org.test.RWrapper class is > instatiated by the RJavaClassLoader. The system class loader however does > not know about myApp.jar anymore. Neither does the PluginClassLoader. So > when the PluginClassLoader loads a plugin class, it can only load classes > that are in the plugin.jar file and as soon as a class from the myApp.jar > file is required by the plugin, it crashes with a > java.lang.NoClassDefFoundError message. > > My question is: how can I force rJava to load the classpath in the system > classloader and not only in the RJavaClassLoader? > > I cannot make the PluginClassLoader know the RJavaClassLoader as my > application also has to run in a non-R environment. > > Thanks for your time, > > Kind regards, > > Ben > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Reasonably Related Threads
- problems with JAVA in JGR library on ubuntu 7.04
- R GUI installation on Linux/SuSE 10.3
- ClassNotFoundException when running distributed job using rJava package
- Bug#123084: r-base: R documentatio search engine unusable with Mozilla 6 (OK with netscape 4.7x) (PR#1202)
- Unable to execute Java MapReduce (Hadoop) code from R using rJava