I'm trying to run a runnable JAR file from R, using the rJava package. This jar has to write and read some files to/from external folders, that are in the same path as the jar file itself, like this:
mypath/myjar.jar
mypath/folder1
mypath/folder2
mypath/input_file1.txt
mypath/input_file2.txt
The program works fine if I call it by opening a console in "mypath" and running the jar the following way:
java -jar myjar.jar input_file1.txt input_file2.txt false
But when I try to run this code in R, using rJava, the code crashes at some point, because it can't find neither mypath/folder1 nor mypath/folder2, even though the working directory is correctly defined as "mypath".
jinit(".",force.init=TRUE) # this starts the JVM
.jaddClassPath("myjar.jar")
jobject <- .jnew("package_name/Main") ## call the constructor
result_java <- rJava::.jcall(obj = jobject, returnSig = "V", method = "main", c("input_file1.txt","input_file2.txt","false"))
In fact, the java program is called, it is able to actually find the input files which are also in mypath, but for some reason crashes when it tries to write to folders in mypath (such as folder1 and folder2) with the error:
Error executing task java.nio.file.NoSuchFileException: folder1/some_file.txt
I really have no idea what's going on, spent hours on this. Am I missing something really obvious here?