Include jar file when creating an R package

此生再无相见时 提交于 2019-11-30 15:06:01

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/3843816/include-jar-file-when-creating-an-r-package

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