I am having some problems with linking a jnilib in java. I receive
Exception in thread "main" java.lang.UnsatisfiedLinkError: no ***.jnlib in java.library.path.
Through my research I found that this could be caused by java not knowing were the file was. So, I told it that it was in the Mac folder. I also added the file to every other folder in the project. None of this helped at all. The project is cross platform so I tried it on windows the dll's loaded just fine when I told java to look in the windows folder. I do not understand why this would work in windows and not on a Mac. Any thoughts or ideas will be welcome.
The exception output is:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no libhidapi-jni-64.jnilib in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at webstart.OmronIO.<init>(OmronIO.java:30)
at webstart.Omron.main(Omron.java:13)
The java.library.path is: /Volumes/UNTITLED/javahidapi/mac.
The path to the jinlib is : /Volumes/UNTITLED/javahidapi/mac.
On OSX, the environment variable DYLD_LIBRARY_PATH is used to find shared libraries (including .jnilib). That variable is what is used to initialize java.library.path.
If you output the value of java.library.path at the point where you attempt System.loadLibrary(), you will see the list of directories searched for the library you are attempting to load.
EDIT
See also http://create-lab-commons.googlecode.com/svn-history/r222/trunk/java/lib/HIDAPI/README.txt, which appears to apply to the specific library you're attempting to load (hidapi), and the way you're attempting to load it (webstart).
I faced the same issue. It was not loading library file in any path, even after using - Djava.library.path in application argument. I am using System.loadLibrary("test"). The library name was libtest.jnilib
The prefix and suffix will be added while executing.
I am using Mac M1 Pro. Unfortunately, it is not supported in ARM based JDKs. Switching to non-ARM JDK solved the issue.
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 have a problem installing jpl library. I installed the latest swipl version (but I tried also unstable versions before):
SWI-Prolog 7.2.3 for Windows 7/8/10 64-bit edition
Then I added dependent paths to environment variables:
Variable: SWI_HOME_DIR
Value: C:\Program Files\swipl
Then I added, to Path these values:
%SWI_HOME_DIR%\lib\jpl.jar;
%SWI_HOME_DIR%\lib;
%SWI_HOME_DIR%\bin
I also added the VM argument like this:
-Djava.library.path="C:\Program Files\swipl\bin"
to make sure that Eclipse sees this folder.
After that I still get the error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Program Files\swipl\bin\jpl.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1855)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.jpl7.JPL.loadNativeLibrary(JPL.java:79)
at org.jpl7.fli.Prolog.<clinit>(Prolog.java:41)
at org.jpl7.Query.open(Query.java:260)
at org.jpl7.Util.textToTerm(Util.java:102)
at org.jpl7.Query.Query1(Query.java:129)
at org.jpl7.Query.<init>(Query.java:120)
I'm 100% sure, that Eclipse sees that jpl.dll file, but in my opinion, it seems that it needs some other libraries.
I know that this thread is probably duplicate of either of these:
jpl.dll: Can't find dependent libraries
JPL Can't find dependent libraries of jpl.dll
but these questions are not answered or the answers doesn't helps in my case.
I added dependent paths to environment variables:
Variable: SWI_HOME_DIR
Value: C:\Program Files\swipl
Then I added, to Path these values:
%SWI_HOME_DIR%\lib\jpl.jar;
%SWI_HOME_DIR%\lib;
%SWI_HOME_DIR%\bin
This is the installation instructions:
Put the three library files (jpl.dll, jpl.jar and jpl.pl) where each can be found:
jpl.dll must be found by the Windows kernel, and can go in any
folder on your PATH environment variable;
perhaps %SWI_HOME_DIR%\bin
or your Windows system folder
jpl.jar must be found by any Java VM's (and compilers) used
with JPL. One possibility is to put it on your global CLASSPATH.
jpl.pl is a Prolog source module, and must be found by any
SWI-Prolog engines used with JPL:
I suggest putting it in %SWI_HOME_DIR%\library and then invoking
make_library_index/1 on that folder (see a SWI-Prolog manual
for details) so that the autoloader can find it.
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 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.