Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run an executable .jar file in an R script?

I am working on a relatively large data analytics project in which an R script I wrote is the primary executable, calling all other bits of code. I can't figure out how to call an executable .jar from my R script, however and I haven't seen this question posted elsewhere... is this a possibility?

like image 418
TayTay Avatar asked Nov 29 '13 18:11

TayTay


People also ask

How do I run an executable jar from command line?

To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]

Does a JAR file need to be executable?

Java Runtime Environment (To Run The file) If you want to run the JAR file, you will need the Java Runtime Environment. If you have the Java Runtime Environment, then all you need to do is to double click on the file name. But it will only work if that particular file is executable.

How do I run an executable JAR file in Windows 10?

Right-click your JAR file and choose Open With > Java(TM) Platform SE Binary. Tip: If you don't see that option in the “Open With” menu, then click “Choose Another App” and you'll see the option. Your JAR file will launch and you'll be able to interact with it.


2 Answers

You can use rJava to create an instance of your java Object. Then you call its methods ..

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
like image 104
agstudy Avatar answered Sep 28 '22 07:09

agstudy


Have you tried

system("path/to/file.jar")
like image 45
Sven Hohenstein Avatar answered Sep 28 '22 06:09

Sven Hohenstein