创建R包时包含jar文件 [英] Include jar file when creating an R package
问题描述
我创建了一个骨架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屋!