I am developing a program that calls R functions from Java using JRI/rJava. I was coding the program in NetBeans on another machine, which was working fine (i.e. able to run the code). I have since then moved to another machine and have been running into problems.
The exact error message I am seeing is this:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: E:\R\R-2.13.1\library\rJava\jri\jri.dll: The specified path is invalid
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at com.rjava.test.rtest.main(rtest.java:64)
Java Result: 1
I have read the FAQs for JRI/rJava, and have been scouring the internet for fixes, but have made no progress. Here is what I have done so far:
Created an environment variable called R_HOME: "E:\R\R-2.13.1"
Added "%R_HOME%\bin\x64" to the PATH environment variable
Added "%R_HOME%\library\rJava\JRI" to the PATH environment variable (this is where jri.dll is located)
Set the required jar files as compile time libraries (JRI.jar, JRIEngine.jar, REngine.jar) in NetBeans
set the following VM options in NetBeans: : -Djava.library.path=E:\R\R-2.13.1\library\rJava\jri (This is where jri.dll is located)
I have restarted my computer to make sure that the changes stick.
To make sure I configured things correctly, I ran the following in the command line:
java -cp E:\R\R-2.13.1\library\rJava\jri\JRI.jar;E:\R\R-2.13.1\library\rJava\jri\examples rtest
And the example java files ran fine. I'm beginning to think my new machine just hates me.
The message indicates that it the path E:\R\R-2.13.1\library\rJava\jri\jri.dll is invalid. Are you sure that path exists? Also, is E a mapped drive that is mapped to a path that has spaces in it? I'm not sure if the spaces are the issue, but it eliminates one issue. I would try just putting the dll in C:\ or somewhere very simple and seeing if it can find it there as a simple test.
Also verify that the -Djava.library.path is being passed as you think it is (you can check that with visualvm or jconsole).
You could try this:
-Djava.library.path=E:\R\R-2.13.1\library\rJava\jri -cp E:\R\R-2.13.1\library
\rJava\jri;E:\R\R-2.13.1\library\rJava\jri\JRI.jar;E:\R\R-2.13.1
\library\rJava\jri\examples
The reason I say this is that, perhaps the .dll also needs to be in the classpath as well as the library path in order for the classloader to load it? Its probably not true, but worth trying. Also is "rJava" correct? Other than that, it looks to me like your doing it right.
To locate JRI installed with rJava, use system.file("jri",package="rJava") in R.
set that path to your path (environment variables in windows),
restart your netbeans. and try to run your program again
Related
I would like to call a Java function that uses Cplex, from Matlab.
At the moment, I am stuck. Below is a list of things I tried, but I am out of ideas. Before I get there, let me list the versions:
Matlab version 8.3.0.532 (R2014a)
Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Eclipse with jre7 and jdk1.7.0_79
I created a package "milp.jar" and try to call the following function from Matlab:
milp.MTsolver.Plan()
In a basic version of my milp.jar, without any Cplex functionality, this goes without problems. Just as soon as I use a Cplex function in my Java class, I get in trouble. I tried the following:
To be able to use Cplex, I added the path to the javaclasspath.txt file in the Matlab folder
prefdir
The command
javaclasspath
in Matlab console indeed shows that this path is added to the Static Java Path.
But then, when calling my cplex dependent function milp.MTsolver.Plan(), I get the following error:
Java exception occurred:
java.lang.UnsatisfiedLinkError: no cplex1262 in java.library.path
java.library.path must point to the directory containing the CPLEX shared library
try invoking java with java -Djava.library.path=...
Following this post, I should first load the library:
java.lang.System.load('C:\Program Files\IBM\ILOG\CPLEX_Studio1262\cplex\lib\cplex.jar');
But this gives the following error:
Java exception occurred:
java.lang.UnsatisfiedLinkError: C:\Program Files\IBM\ILOG\CPLEX_Studio1262\cplex\lib\cplex.jar: %1 is not a valid Win32 application
At his point, I tried another approach. I just copied the cplex.jar into the Matlab root folder. No success. Nor any succes when just copying the cplex.jar in the project folder in Matlab.
Then, I tried to find a cplex1262.jar, but I only found a cplex1262.dll. So I added this path to the Static Java Path. This gives the following error:
Java exception occurred:
java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
The same error occurs when I run the following in the Matlab console:
java.lang.System.load('C:\Program Files\IBM\ILOG\CPLEX_Studio1262\opl\oplide\plugins\ilog.odms.ide.opllang.win32.win32.x86_64_12.6.2.0\cplex1262.dll');
A last thing I could try comes from an answer in this post.
Here, he sets
-Djava.library.path=...
in the VM Options field, but in Netbeans. I could try to do something similar in Matlab, but I have not figured out yet how.
Last, I just added the directories containing cplex.jar and cplex1262.dll to the PATH environment variable. No luck there either.
Another important note might be that I have no problem running my code in Eclipse, including Cplex functionality! It might also be worth mentioning that, in between changes, I restarted Matlab to be sure that all changes in path settings took effect.
I hope to have stated my problem clearly enough. Any suggestions on how to proceed are very welcome!
I was able to find a quick and dirty solution, which is ok for now.
First I tried to add the path to the directory containing cplex1262.dll to the
'java.library.path' as follows:
java.lang.System.setProperty('java.library.path', [path to dir])
But that did not work for me. In a quick and dirty manner, I looked up what paths were already included in this property, with the following command.
>> java.lang.System.getProperty('java.library.path')
ans =
C:\Program Files\MATLAB\R2014a\bin\win64;C:\Program Files\MATLAB\R2014a\sys\jxbrowser\win64\lib
And just copy/pasted the cplex1262.dll in the \lib directory.
That worked.
I have a laptop with a Windows 7 OS 64-bit. I'm trying to set up the Java compiler so when I type in "javac" in the command prompt, it will compile the Java file I want. I've had it done on my laptop before but someone did it for me. They went to the Environment Variables under the Advanced System settings, then edited the "PATH" so that it would recognized the compiler. So I did the exact same thing, I copied the file location of javac from ProgramFiles, and put it in PATH. It still does not compile my Java files. It says:
"javac" is not recognized as an internal or external command.
And before you ask, I did search through other forums on this site to see if there was an answer that can help. There are similar situations to mine but the solutions did not help me.
As of now, this is the file path that I tried copying into PATH:
C:\Program Files\Java\jdk1.7.0_25\bin This leads to a file marked javac. So far I'm still unsuccessful with setting up the compiler.
It looks correct. Did you restart the Command prompt every time you changed the PATH variable ? Also there's supposed to be only one path variable, so you're supposed to edit the existing one, entries are separated by a semi-colon (;).
I am getting a error message like this:
The library libraryname.dll could not be loaded by Windows. Make
sure that the library is in you Path environment variable. Exception
in thread "main" java.lang.UnsatifiedLinkError: no libraryname in
java.library.path.
This error is from me trying to run a jar file on Windows XP via cmd. I am wondering, where exactly is java.library.path? I've already added C:\Program Files\Java\jdk1.6.0_26 to my PATH but it still gives me the error. How would you go about debugging this?
Thanks.
You can simply pass java.library.path as a system property as shown below:
java -Djava.library.path=<path_to_dll> <main_class>
First you need to find out where the libraryname.dll is and add it above in "path_to_dll".
The error is basically saying it cannot find your native libraries. Java tries to locate your library by looking into java.library.path property
It's an System environment that you need so Java can find your native libraries when you run your application. Several ways to do it:
Use java -Djava.library.path=[path to your library] when running your program
From the code you could also do.
System.setProperty( "java.library.path", "/path/to/libs" );
Set it up from your IDE. An example for Eclipse can be found in this SO question How to set java.library.path from eclipse
EDIT: A good comment below pointed out that #2 will not working 100% because you might not set this prior to calling getProperty(). Missed that point and thanks for pointing that out.
I am able to run a java program with some dependencies from cmd line on my mac, but when I try to run it on a linux SUSE 11 box I have it comes back with:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no myNativeLib in java.library.path
This is the cmd line I am running:
java -Djava.library.path=../lib -cp ../jar/a-jar.jar:. MyMainClass
Any help appreciated!
I would recommend to use absolute path for java.library.path. At least you eliminate possible problems with relative path resolution.
Also, just to confirm, you do have Linux library in the lib, right? Mac one will not work.
I'm going go out on a limb and assume(at the risk of a bunch of downvotes) that you are trying to use oracle's native database driver.
If it is indeed a database driver that you are using, you can bail on the native version and simply include the .jar thin client on your classpath by using the -cp extension. This may require some code changes such that you are not attempting to invoke the native driver.
If you are hell bent on using a native driver or you need to because the code relies on it. you need to make sure that the java.library.path variable is set to a directory containing the binary driver files(typically denoted with a .so extension).
Also make sure these driver files(since they are native binary) have been compiled for your distribution of linux and not just conveniently copied from the mac install.
If you are not doing any of these things feel free to ignore everything I've said.
I am new to java.I have written some python scripts and need to run them from java as desired by my mentor(these scripts are to be deployed on a server).So I have installed Jepp on my windows xp.However when I run
C:\Program Files\Jepp>java -classpath jep.jar jep.Run console.py
I get
java.lang.UnsatisfiedLinkError: C:\WINDOWS\system32\jep.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at jep.Jep.<clinit>(Jep.java:136)
at jep.Run.run(Run.java:54)
at jep.Run.main(Run.java:153)
I have included the system32 folder containing jep.dll and the Program Files\jepp folder in PATH env. variable but still it is showing the same error.Are there any other directories that need to be included in the PATH variable?
Also in the readme file in jepp dir. for installation,it is given:
Also, you'll likely need to add -Djava.library.path='path to
Release folder' for testing. Or copy and register the DLL in the
System directory.
The jep.dll is already present in system32 directory.What other DLL might have been referred to here.
Ive also tried
C:\Program Files\Jepp>java -classpath jep.jar jep.Run console.py -Djava.library.path='C:\Program Files\Jepp'
but it still gives the same UnsatisfiedLinkError :(
Am I wrong in adding the -Djava.library.path command as in above or is it supposed to be added somewhere else?
I am so confused and getting all kinds of doubts as i've been struggling with this for the past 2 days :( .Even the online documentation is not so detailed and helpful.I would really appreciate any suggestions regarding this....
thanks in advance!