UnsatisfiedLinkError - Unable to load library - Source library not found in resource path

I have a runtime error while trying to start Tess4J:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302': Native library (win32-x86-64/libtesseract302.dll) not found in resource path ([myproject/target/classes/, ...some jars...]) 

My questions:

1) What exactly is he trying to find and where?

2) Why is he apparently looking for the directory myproject/target/classes/ ? I have not installed it anywhere.

3) Why does it ignore the "source directory path" that I set for tess4j.jar in the descripto user library in Eclipse? My dll files are there. If it does not ignore the path, it will find the DLLs.

4) Why does this probably add a DLL name using win32-x86-64/ ? I have not installed anything. Is this standard prefix of some API?

5) What is a "resource path"? How to install it?

+8
java eclipse dll jni jna java-native-interface
source share
7 answers

Like the error, it looks for win32-x86-64/libtesseract302.dll in java.class.path . Apparently, part of your class path includes myproject/target/classes .

The prefix is ​​the platform and architecture of the downloadable shared library, which allows you to include shared libraries in a single archive for different purposes. If JNA cannot find the requested library name in the system boot path, it tries to find it in your resource path (retrieving it if necessary). Therefore, if you put the DLL in a jar file, you need to specify the win32-x86-64 prefix to load it.

The "path to resources" is nominally your path to the class; basically anywhere reachable by ClassLoader.getResource() .

+5
source share

The error is related to an attempt to load 32-bit DLLs into a 64-bit JVM. A possible solution is to switch to a 32-bit JVM; alternatively, use the 64-bit Tesseract and Leptonica libraries .

+3
source share

Why don't you use the JNA API http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm to download your own library? After you put in your project path, you add this code

NativeLibrary.addSearchPath("libtesseract302", "your native lib path"); make sure you have this libtesseract302.dll file, usually it is located in the windows32 folder.

For example, if your libtesseract302.dll file is somewhere in c:/abcv/aaa/libtesseract302.dll , then you simply set the path as follows NativeLibrary.addSearchPath("libtesseract302", "c:/abcv/aaa");

I do not know what the path to the window c:/abcv/aaa or c:\\abcv\\aaa\\ looks like

if you need an easier way, just put all the necessary DLL file in the Windows32 folder, the JVM will take care of that.

Another problem may be that you did not install the application correctly or the application version was not removed with your jar version. try installing the latest application and download the latest jar to try again. Hope this helps :)

+2
source share

Had the same problem sorted by the following lines

System.load ("/USR/local/Library/liblept.so.5")

System.loadLibrary ("tesseract")

In your case, these may be different libraries, but in the end it is almost the same: just load the libraries you need manually.

+2
source share

I had the same problem and found that this "resource path" was not set to "source directory path".
However, you can add new folders to it using the "Add external class folder" on the "Library" tab, even if this folder does not contain class files, but the source library files (for example, a DLL in Windows).

0
source share

A few days ago I came across the same error message while trying to load a C ++ DLL using JNA. It turned out that the reason was the missing DLL, on which my DLL depended.

In my case, the redistributable MS Visual Studio 2012 was distributed, which I then downloaded and installed on the machine, and the problem disappeared. Try using Dependency Walker to find the missing libraries and install them.

0
source share

I encountered a similar problem, I tried all the answers above, but this did not solve my problem, finally I checked with the source where I got the dll from and found that I did not have Windows 2012 redistributable installed, the dll was built using this, as soon as I set this, the exception is gone.

0
source share

All Articles