【问题标题】:Running Java in R with 2 files .java and .jar使用 2 个文件 .java 和 .jar 在 R 中运行 Java
【发布时间】:2019-01-07 11:51:06
【问题描述】:

我创建了一个 .java 文件,它使用 .jar 作为 Eclipse 的外部库文件。我只需要 .java 中的一点公共静态函数就可以在 R 中运行,也许来自 R 中的“jobject”调用?有没有人怎么做?

最接近的解决方案来自https://stackoverflow.com/a/20291982/2842390

library(rJava) .jinit(PATH_TO_YOUR_JAR) # this starts the JVM 

jobject <- .jnew("yourJavaClass")  ## call the constructor 

.jcall(jobject ,"I",method="YOUR_METHOD") ## call a method

但我不能将我的 .java 文件放在“yourJavaClass”中,因为它会导致 .jnew("hello3.java") 中出现错误:java.lang.ClassNotFoundException。

非常感谢您的帮助!

【问题讨论】:

标签: java r


【解决方案1】:

你可以打电话

.jaddClassPath('path/to/your/file.jar')

然后您可以使用该文件中的任何类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2014-06-07
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    相关资源
    最近更新 更多