创建 R 包时包含 jar 文件
我创建了一个骨架 R 包:
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,我失败了。
我能够使用它来工作,
.jinit
.jaddClassPath("../lib/jarFileHere.jar")
但 rJava 文档明确表示不要使用 .jinit,因为当代码用作包时它不会工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使您的结构如下:
有关如何在包中包含 java 的示例,请查看 helloJavaWorld 包。
另请查看 Deducer 和 DeducerplugInExample。 Deducer 的网络手册上有一个关于在包中包含 java 代码的教程:
http://www.deducer.org/pmwiki/pmwiki.php ?n=Main.Development#suaptijc
Make your structure like:
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