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.
Related
I know, this is not the first library path problem, but I really don't know what the problem is.
I need a KernelWrapper library for my project, and including it on Linux is no problem at all.
However, when I try to include it in Mac (over Terminal or directly in the IDE), I always get
Exception in thread "main" java.lang.UnsatisfiedLinkError: no KernelWrapper in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at cTools.KernelWrapper.<clinit>(KernelWrapper.java:6)
at shell.main(shell.java:18)
I printed out the library path using
System.out.println(System.getProperty("java.library.path"));
and it shows me that the path of the folder is correct and included. However, the KernelWrapper class somehow doesn't work properly. But it is the exact same folder which was included on Unix.
What am I missing?
The UnsatisfiedLinkError is thrown when an application attempts to load a native library like .so in Linux, .dll on Windows or .dylib in Mac(in your case) and that library does not exist. Specifically, in order to find the required native library, the JVM looks in both the PATH environment variable and the java.library.path system property.
First of all you must verify that the parameter passed in the System.loadLibrary method is correct and that the library actually exists. Notice that the extension of the library is not required. Thus, if your library is named SampleLibrary.dll, you must pass the SampleLibrary value as a parameter.
Moreover, in case the library is already loaded by your application and the application tries to load it again, the UnsatisfiedLinkError will be thrown by the JVM. Also, you must verify that the native library is present either in the java.library.path or in the PATH environment library of your application. If the library still cannot be found, try to provide an absolute path to the System.loadLibrary method.
In order to execute your application, use the -Djava.library.path argument, to explicitly specify the native library. For example, using the terminal (Linux or Mac) or the command prompt (Windows), execute your application by issuing the following command:
java -Djava.library.path= "<path_of_your_application>" –jar <ApplicationJAR.jar>
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 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
I have application which use JNA and gets the audio and video. It works in my Linux box. But when i am testing it in Windows. It just never working. Because i am still learning, i will appreciate your suggestion how to fix it, i already spent few days and weeks only to work it out, but just dont get this why JAVA does not work simply, its a cross platform. Why should it require again System path or etc configuration.
I am totally lost now, why it works in Linux and it does not work in Windows XP ? How can i run it then ?
Inside the lib direcotry i have my JNA and Audio libraries.
C:\Documents and Settings\test\Desktop\test>dir
Volume in drive C has no label.
Volume Serial Number is 680F-0963
Directory of C:\Documents and Settings\test\Desktop\test
19/12/2010 22:09 <DIR> .
19/12/2010 22:09 <DIR> ..
19/12/2010 22:09 51.791 Audio.jar
19/12/2010 22:09 <DIR> lib
1 File(s) 51.791 bytes
3 Dir(s) 487.002.112 bytes free
Now trying to run Audio.jar, gets Fail 1:
C:\Documents and Settings\test\Desktop\test>java -Djava.library.path=~/jni -jar
Audio.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load librar
y gstreamer-0.10
at org.gstreamer.lowlevel.GNative.loadWin32Library(GNative.java:83)
at org.gstreamer.lowlevel.GNative.loadLibrary(GNative.java:43)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:42)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:39)
at org.gstreamer.Gst.<clinit>(Gst.java:59)
at video.MyVideo.simpletest(MyVideo.java:31)
at sipphone.MainApplet.run(MainApplet.java:58)
at sipphone.MainApplet.main(MainApplet.java:43)
Fail 2:
C:\Documents and Settings\test\Desktop\test>java -Djna.library.path=. -jar Audio
.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load librar
y gstreamer-0.10
at org.gstreamer.lowlevel.GNative.loadWin32Library(GNative.java:83)
at org.gstreamer.lowlevel.GNative.loadLibrary(GNative.java:43)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:42)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:39)
at org.gstreamer.Gst.<clinit>(Gst.java:59)
at video.MyVideo.simpletest(MyVideo.java:31)
at sipphone.MainApplet.run(MainApplet.java:58)
at sipphone.MainApplet.main(MainApplet.java:43)
You'll need to have the DLL installed, or at least in your JNA library path as others have pointed out.
It does add an extra dependency on Windows. It would be an extra dependency on Linux but gstreamer is preinstalled by your distribution. I ran into this same problem when I was making something to use a USB port from Java.
The only solution I know of to avoid the DLL would be to have a second version of the code you could call on Windows that would only use Win32 stuff (i.e. stuff that ships with Windows) but that would be a very large undertaking.
trying to run mediarenderer from cling package, I had the same error on windows xp.
i got the right libgstreamer-0.10.so from package GStreamer-WinBuilds-GPL-x86-Beta04-0.10.7.msi found in https://code.google.com/archive/p/ossbuild/downloads
once installed (environment variables PATH (for dependencies) and OSSBUILD_GSTREAMER_DIR set),
in a prompt, I was finally able to run mediarenderer using the following syntax to introduce lib's path :
Z:\Downloads\cling-distribution-2.1.0\cling-distribution-2.1.0\mediarenderer\target>java -Djna.library.path="C:\Program Files\OSSBuild\GStreamer\v0.10.7\bin" -jar cling-mediarenderer-2.1.0-standalone.jar
hope this helps as a starting point !
For Fail 1: I don't believe that the ~/ syntax will work on Windows. Try %HOME%\ instead. The tilde expansion happens in Bash, so things are a bit different in Windows.
For Fail 2: It doesn't look like the .dll is in your test directory, and you're setting the jna.library.path to ..
If the .dll's are in your lib directory, then shouldn't the paths be set to that directory, instead of ~/jni and .?
I am running jython to connect to Bladelogic managers for which i need to connect to it. When i try to do it. It says following Error:
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: no XJNIService in java.library.path.
Can you please help me to resolve this issue.
Regards
Gnash-85
Some class you are using requires native libraries and the JVM cant find them. You need to set LD_LIBRARY_PATH on linux/unix or start with the property -Djava.library.path=PATH to where the libraries are located (the later works on both linux and windows).
For example: "LD_LIBRARY_PATH=/my/libs java -cp foo jython.repl"
There should be a flag you can pass to the jvm to output diagnostic info regarding jni loads.