I am trying to deploy my application that invokes native calls using JNA library, but I get the following exception.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'myCustomDLL': Native library (win32-x86-64/myCustomDLL.dll) not found in resource path ([myproject/target/classes/, ...some jars...])
What do I need to do in order to invoke the function correctly?
Any help much appreciated
You must put your dll library (with native code) on application java.library.path.
See :
http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/
Edit:
Post your project layout here. And how you run your app.
Check whether the DLL is executable.
Check the dependant DLLs are all executable.
With windows explorer, right click on DLL -> property -> security and verify execution rights.
Actually I found the answer to this. Basically, I needed to install Microsoft Visual C++ Redistributable package to install all the necessary DLLs needed for JNA to work. Thanks for other responses to this question.
Related
In my app, I am adding third party hardware connectivity and using their provided code for java. Also using jna.jar to interact with that code as it uses native library to load some .so files. It throws the error:
java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.) Please help where can I get the jar with android-arm/libjnidispatch.so in it.`
I tried adding android-arm.jar which is having libjnidispatch.so separately but compiler is looking for jna.jar's path. Thanks!
Extract the com/sun/jna/linux-arm/libjnidispatch.so from the jar file
put the .so file in the following directory (when using android studio): yourproject\app\src\main\jniLibs\armeabi-v7a\libjnidispatch.so
And also please note that linux architecture != android architecture (google uses a different c library (bionic), which is a different one than the normal linux distributions)
For all architectures see:
https://github.com/java-native-access/jna/tree/master/lib/native
Which version of JNA do you use? (There was a bug in JNA 4.2.2/4.3.0 which might also be a cause)
I'm working with some java code wich loads an unmanaged dll, just as the following:
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
It works fine from eclipse or console.
Next step: I'm using IKVM tools to get a managed dll from my java app (ikvmc.exe). Everything works fine and my dll is built perfectly. In fact, I've imported that library in a Test Solution (and I've add all IKVM refereces needed -IKVM.Core.JDK, IKVM.Runtime.JNI, etc-).
Well, here is the problem: when I run C# code the java call to System.loadLibrary(...) fails and I get an "UnsatisfiedLinkError: Can't load absolute_path_to_my_dll.dll". Absolute path is ok and dll is there.
Any help? Thanks in advance.
Edit 1
I'll try to explain more in detail:
Java step
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
If path is not correct this call gives the "UnsatisfiedLinkError" mentioned above. This is not the case, everything works well. The dll file is a 32 bit one, so I compiled this java project with jre7 x86 (in 64 bit mode loadLibrary call falis, obviously, saying we can't load 32 bit dll in 64 bit AMD machine).
Ikvm step
Now I compile java code in a managed dll wich can be imported in a .net project. First of all I export my java project to a jar file, "myJar.jar". Then i apply ikvmc.exe to generate a managed dll, let's say "myNewDll.dll".
ikvm.exe -target:library -out:"myNewDll.dll" "myJar.jar"
This step works nicely and i get a new dll I can import in my VS project.
C# step
Now I create a new VS tester solution. I add "myNewDll.dll" as reference so I can use it in my C# code. Also, I add IKVM.Core.JDK reference (if not, project can't compile) and configure project in 32 bit mode. Problems start here:
Running this setup gives "IKVM.Runtime.JNI error". I've added that reference.
Running again gives "can't find ikvm-native". As I can't add ikvm-native-win32-x86.dll or ikvm-native-win32-x64.dll as reference I put both of them in output path (bin/Debug).
Next try it gives the "UnsatisfiedLinkError: Can't load xxx.dll".
How can it be possible if that dll is loaded flawlessly in java step?
Annother try
Just before start crying I tried annother way: I created a java main program that only called Foo(). Then I generated an executable file with ikvmc.exe tool and called it in windows console. It gave me the same error, UnsatisfiedLinkError so maybe it's ikvmc.exe problem but I can't understand why.
Any idea?
Edit 2
Good news. It seems I've solved the problem. First of all, I had to add -platform:x86 to ikvmc.exe call (step 2). The dll generated was succesfully imported in my C# project and it works fine if we run in execution mode (NOT debugging). If I try to debug in VS it gives me System.Runtime.InteropServices.SEHException.
Is there any kind of bug related to debugging native code (dll loaded in java code) under native code (that java code loaded in C# using ikvm)?
Is your dll a 32 bit and you run it on a 64 bit platform?
If yes then the problem is that IKVM is platform independent. This means on a 64 bit system it runs 64 bit process.
To solve this you need a 64 bit version of your dll or mark ikvm.exe as 32 bit process.
Adding an option of reference to IKVM.OpenJDK.Core.dll at ikvm's /bin directory will resolve the error.
Maybe the .jar file needs some native DLLs, which was same as Native library location parameter of JAR in Eclipse. If so, find the native DLLs and copy them to de /bin directory of IKVM, and make ikvmc to load them automatically.
That's all what I've found out. Try and see if it would bring some ideas.
I am stuck one point.
I am getting this error from eclipse
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
I tried few links and tried to solve problem, but I am unable to do so.
I changed Jar file location, no output
I also tried to change eclipse.ini, but it also couldn't resolve it.
What should I do?
If any other information or image is required regarding issue, I will provide. ask me in comments.
Thanks
Duaan
In your run configuration in Eclipse, add
-Djava.library.path=<path to JOGL>
under Arguments -> VM Arguments.
When you run outside of Eclipse, you'll need to make sure the native libraries are accessible too. As Hot Licks mentioned, these are the native libraries (e.g. dll files in Windows), not just the Java class files that come with JOGL.
I'm having this issue with an app I have written for a Scanner running windows mobile 5.0. I have no idea what it means, can anyone with some Java Cre-Me, windows mobile experience lend some assistance please??
Error given on execution:
java.lang.UnsatisfiedLinkError: no SymbolJavaApi in java.library.path
at java.lang.ClassLoader.loadLibraryInternal()
at java.lang.ClassLoader.loadLibrary()
at java.lang.Runtime.loadLibrary0()
at java.lang.System.loadLibrary()
at
at com.vmt.plugins.symbol.barcodescanner.services.ScannerImplementation.read()
at com.vmt.plugins.symbol.barcodescanner.ScannerPlugin.invoke()
at ScannerTest.startScanning()
at ScannerTest.createwindow()
at ScannerTest.main()
For UnsatisfiedLinkError, the JDK states:
Thrown if the Java Virtual Machine cannot find an appropriate
native-language definition of a method declared native.
That means that there is a method inside ScannerImplementation.read() that is a native call definition that it can't in the java.library.path or any system defined libraries.
What this means is that the DLL that is needed for your ScannerImplementation isn't registered in the Java LIB path and thus the JVM can't do a native call.
I hope this helps.
The Java class loader tries to access the Symbol API but can not find the required libraries in the given library path.
On a desktop system I'd say you need:
Either extend the class path accordingly or
Copy missing external DLLs to the path where your application resides
I'm sure that Symbol/Motorola has some examples where you can see how to do that - maybe you need to install the classes to the device first using a CAB file.
I'm coming from a .NET background and for that, there's a Symbol API CAB file which installs required DLLs to the device.
I am working on a Java project in which I have to use a third party dll (let's say abc.dll). So I created a native header file using JNI.
Then I created a dll project on vs2005 (typical win32 app.) and added that header file created by JNI. I selected clr old syntax support for the project and added the abc.dll as a reference to my project.
Up to now, everything is ok. Here is the problem. I implemented the methods defined in the header file using some methods from the abc.dll. abc.dll has a class called "abc" and that's what I do:
abc *abcObj = new abc(); abcObj->callSomeMethod();
I take a build from the solution, everything is ok. But when I run my Java program, I get an error from the JVM telling that native code broke down?!?! I debugged it and the problem is in new(). It simply cannot instantiate the abcObj.
Then I tried with a c++ app using that abc.dll. It worked.
I think there must be problem with JNI or that managed/unmanaged thing. I am not really experienced at c/c++ so I don't understand so much (at least I don't have time to understand for now). Only thing I try to do is create a wrapper dll using the third party dll and use the wrapper dll in my java app.
Any help will be appreciated.
Thanks in advance...
-haydar
edit: I have all the dlls that are needed by my third party dll.
I have solved the problem. The problem was that I was creating the project as a win32 application and choosing dll then. I created a clr application and everything went well. I followed the instructions from here.