I am currently working on developing an R package to integrate java code within R. However, I am having issues trying to properly call the java class methods. So far I have independently developed and compiled a java program into a class file and then packaged it up as a jar file. A sample of my code is as follows:
library(rJava)
.jinit()
.onLoad <- function(lib, pkg) {
pathToSdk <- paste(system.file(package = "mailViz") , "C:\\path\\to\\libs", sep="")
jarPaths <- c(paste(pathToSdk, "mail.jar", sep=""),
paste(pathToSdk, "mailReader.jar", sep="")
)
.jpackage(pkg, morePaths=jarPaths)
attach( javaImport( c("java.lang", "java.io", "java.mail", "java.util", "java.text")))
packageStartupMessage( paste( "mailViz loaded. The classpath is: ", paste(.jclassPath(), collapse=" " ) ) )
}
# get method arguments for the class
#.jmethods("mailReader","readEmailInfo")
z=.jcall("mailReader", "Ljava/lang/String;", "readEmailInfo", "username", "password")
However, when I execute the .jcall function I receive an error:
Error in .jcall("mailReader", "Ljava/lang/String;", "readEmailInfo", "username", :
method readEmailInfo with signature (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; not found
I tried multiple ways of changing the arguments but no luck. When I run .jmethods("mailReader") on the class file it lists all the methods available:
[2] "public java.lang.String mailReader.readEmailInfo(java.lang.String,java.lang.String)"
So, I am lost in how to make the proper call passing two arguments (username, password) to the java class file.
Any thoughts? Thanks in advance,
P
I have resolved this issue and the key here is to use the
mailReader = .jnew("mailReader")
call so that R has access to this class before making a call in the
z = .jcall(mailReader, "S", etc....)
By default, R has access to the static java methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With