开发者

Include jar file when creating an R package

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 <- 开发者_如何学Pythonfunction(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.


Make your structure like:

inst
 java
  jarFileHere.jar 
R
 r_code_file.R

For examples on how to include java in your package look at the helloJavaWorld package.

Also take a look at the source of Deducer and DeducerplugInExample. There is a tutorial on including java code in your package available on Deducer's web manual: http://www.deducer.org/pmwiki/pmwiki.php?n=Main.Development#suaptijc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜