如何在创建R包时包含jar文件?

时间:2023-01-19 20:58:08

I created a skeleton R package:

我创建了一个骨架R包:

lib
 jarFileHere.jar 
R
 r_code_file.R

The r_code_file.R tries to references a class file in jarFileHere.jar:

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", "") 

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

但是由于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.

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

1 个解决方案

#1


9  

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.

有关如何在包中包含java的示例,请查看helloJavaWorld包。

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

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

#1


9  

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.

有关如何在包中包含java的示例,请查看helloJavaWorld包。

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

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