I created a skeleton R package:
lib
jarFileHere.jar
R
r_code_file.R
The r_code_file.R tries to references a class file in jarFileHere.jar:
library("rJava")
library("rjson")
.onLoad <- function(libname, pkgname) {
.jpackage(pkgname, lib.loc=libname)
}
.onLoad("packagename", "../lib/jarFileHere.jar")
.jnew("com/test/ClassHere", "")
But I get a failure due to java.lang.NoClassDefFoundError.
I was able to get it to work using
.jinit
.jaddClassPath("../lib/jarFileHere.jar")
but the rJava docs explicitly says not to use .jinit because it won't work when the code is used as a package.