创建R包时包含jar文件 [英] Include jar file when creating an R package

查看:403
本文介绍了创建R包时包含jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个骨架R包:

I created a skeleton R package:

lib
 jarFileHere.jar 
R
 r_code_file.R

r_code_file.R 尝试引用类文件在 jarFileHere.jar

library("rJava")
library("rjson")

.onLoad <- function(libname, pkgname) {
  .jpackage(pkgname, lib.loc=libname)
}

.onLoad("packagename", "../lib/jarFileHere.jar")

.jnew("com/test/ClassHere", "") 

但由于java.lang.NoClassDefFoundError而导致失败。

But I get a failure due to java.lang.NoClassDefFoundError.

我能够使用

.jinit
.jaddClassPath("../lib/jarFileHere.jar")

但是rJava文档明确表示不使用.jinit,因为当代码是用作包。

but the rJava docs explicitly says not to use .jinit because it won't work when the code is used as a package.

推荐答案

使你的结构如下:

inst
 java
  jarFileHere.jar 
R
 r_code_file.R

For有关如何在包中包含java的示例,请参阅 helloJavaWorld 包。

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

另请查看 Deducer DeducerplugInExample 。在Deducer的网络手册中有一个关于在你的包中包含java代码的教程:
http://www.deducer.org/pmwiki/pmwiki.php?n=Main.Development#suaptijc

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

这篇关于创建R包时包含jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆