java.lang.UnsatisfiedLinkError: Unable to load library - java

DLL INSTANCE = (DLL) Native.loadLibrary(Settings.getSingletonInstance().getProperty("default.ergoPointer.path"), DLL.class);
I store the dll path in settings file. When i take output of
Settings.getSingletonInstance().getProperty("default.ergoPointer.path"
here : C:\Users\Argenit\Desktop\aaa\dll\ErgoPointer_64_Bit.dll
Error part :
java.lang.UnsatisfiedLinkError: Unable to load library
'C:\Users\Argenit\Desktop\aaa\dll\ErgoPointer_64_Bit.dll': Native
library
(win32-x86-64/C:\Users\Argenit\Desktop\aaa\dll\ErgoPointer_64_Bit.dll)
not found in resource path
([file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/bin/,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/resources/,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/fits.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/json.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/junit-4.8.2.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/kdu_jni.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/log4j-1.2.16.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/JNA/jna-4.1.0.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/JNA/jna-platform-4.1.0.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/ini4j-0.5.4.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/JNA/,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/gluegen-rt.jar,
file:/C:/Users/Argenit/Desktop/Pathology_JAVA/Digital_Pathology/lib/jogl.jar])
If i add (dll) as a external class folder in project and write : loadLibrary("ErgoPointer_64_Bit"), it works in this machine but when i take the runnable jar, it couldn' t find ErgoPointer_64_Bit so i want to give absolute path of dll. But it doesn' t work for me.
I also tried :
C:\Users\Argenit\Desktop\aaa\dll\ErgoPointer_64_Bit
dll\ErgoPointer_64_Bit
ErgoPointer_64_Bit
dll\ErgoPointer_64_Bit.dll
ErgoPointer_64_Bit.dll

Set the system property java.library.path before the call Native.loadLibrary() with just the base name.
System.setProperty("java.library.path",
"C:\\Users\\Argenit\\Desktop\\aaa\\dll;"
+ System.getProperty("java.library.path"));
DLL INSTANCE = (DLL) Native.loadLibrary("ErgoPointer_64_Bit", DLL.class);
You can also set the java.library.path on the command line. eg.
java "-Djava.library.path=C:\Users\Argenit\Desktop\aaa\dll\" -jar somejar.jar

Related

How to solve could not find or load mainclass error?

I am getting this error if I add new component to my frame if I remove it then it works.
I done this troubleshooting
(1)deleting index folder and restart computer and netbeans
(2)increased heap size in conf file
(3)set environment variable in windows system as
:-User variable name = CLASSPATH
:-variable value = C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program Files (x86)\Java\jre1.8.0_40\bin;.
:-System variable name :-Path
:-System Variable value:-C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program Files (x86)\Java\jre1.8.0_40\bin
but the problem persists
if i add new component(radiobutton,label,scrollpane) it gives me this error:
you can try Clean and build your project, if it doesn't work, you can check the posts from
Netbeans - Error: Could not find or load main class ,
Error: Could not find or load main class (netbeans and java)
or
What does "Could not find or load main class" mean?
With Java 11 you can start a class from the terminal with
java classname.java

Unable to Load Dependent SO file in LInux

I am new to linux. I am trying to load a SO file in Ubuntu using Java. The file that I have specified in the java method "System.load(/home/ab/Downloads/libtesseract.so)" loads fine but its dependent so file placed in the same place as "libtesseract.so" is not found. Here is the error message I get. Error: UnSatisfiedLinkError and says "liblept.so.4" cound not be found. This so file is placed in the same location as libtesseract.so. When I place "liblept.so.4" in the "/lib". It is able to load this so file from. So what I understood is that for, its not for java to load the dependent so. It has to be loaded by ubuntu. So I tried a simple application to load this by setting the PATH variable with the location of the so file. And exported the java code into a jar and tried to run this jar file from terminal as the path variable is not persistent for entire system. It worked fine. So I tried to do the same thing programmatically by using the code below to its not working. Please advice. TIA
Code:
ProcessBuilder pb = new ProcessBuilder("/bin/sh");
Map<String, String> envMap = pb.environment();
envMap.put("LD_LIBRARY_PATH", "/home/ab/Downloads");
envMap.put("PATH", "/home/ab/Downloads");
Set<String> keys = envMap.keySet();
for(String key:keys)
{
System.out.println(key+" ==> "+envMap.get(key));
}
System.load("/home/ab/Downloads/libtesseract.so");
As far as I know you can't really modify the environment variables in Java "on-the-fly". That means you should set both LD_LIBRARY_PATH and PATH before running the java.

Java JNI on Mac using Eclipse giving UnsatisfiedLinkError

I am using Eclipse Java and Eclipse C/C++ on OSX Yosemite to create a simple Java JNI application. Here are the steps I performed
Wrote a class on Java Eclipse with native method.
Using this class, created a C header file using javah executable and included the the header file in Eclipse C/C++. On building the C code, .so file is created.
Then I added the path to .so file using eclipse (Run/Run Configutations/Java Application/Environment) by setting variable name as PATH and value as %PATH%/Users/XXXX/Documents/JniWorkspace/JniExampleLibrary/Debug
Here is Java code to load the C library:
public class JniExample {
static {
System.loadLibrary("JniExampleLibrary");
}
public native void callNativeMethod();
....
....
}
But still I am getting the error as shown below:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no JniExampleLibrary in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1087)
at code.example.JniExample.(JniExample.java:5)
at code.example.Main.main(Main.java:8)

Ghost4J. java.lang.UnsatisfiedLinkError: Unable to load library 'gsdll64'

I included Ghost4J 0.45 into my project using Maven and installed Ghostscript into C:\Program Files\gs\gs9.06.
But I still get an error java.lang.UnsatisfiedLinkError: Unable to load library 'gsdll64'.
I added into PATH env variable directory where located 'gsdll64.dll' (i.e. C:\Program Files\gs\gs9.06). Also tried launch application using -Djava.library.path=/path/to/dir.
But I alwways get UnsatisfiedLinkError (but when I launch using JVM argument -Djava.library.path I get ClassNotFound exception (Eclipse can't find Main class, but I manually point Eclipse to Main class when I laucnh my app))/
Does it work if you copy gsdll64 to your working directory? :-)
if u want to use a system property
-Djna.library.path=/path/to/dir should be used instead of -Djava.library.path=/path/to/dir

using matlabcontrol API to call to call matlab function from Java within Netbeans

I have been trying to edit the the following matlabcontrol code but still there is an error when I run it. Please friends help me out!
package matcontro;
import matlabcontrol.*;
public class HelloWorld
{
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
// create proxy
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
// call builtin function
proxy.eval("disp('hello world')");
// call user-defined function (must be on the path)
proxy.eval("addpath('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
proxy.feval("myfunc");
proxy.eval("rmpath('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
// close connection
proxy.disconnect();
}
}
The error that I get is below;
run:
Exception in thread "main" matlabcontrol.MatlabConnectionException:
Could not launch MATLAB. Command: [matlab, -r, javaaddpath
'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath
Libraries\matlabcontrol-4.0.0.jar';
matlabcontrol.MatlabClassLoaderHelper.configureClassLoading();
javarmpath 'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath
Libraries\matlabcontrol-4.0.0.jar';
matlabcontrol.MatlabConnector.connectFromMatlab('PROXY_RECEIVER_01caa56d-9ed7-4e39-a45b-345051024d49',
2100);]
at
matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:305)
at
matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
at
matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
at matcontro.HelloWorld.main(HelloWorld.java:21)
Caused by: java.io.IOException: Cannot run program "matlab": CreateProcess error=2, The system cannot find the file specified at
java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) at
matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:292)
... 4 more
Caused by: java.io.IOException: CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:188)
at java.lang.ProcessImpl.start(ProcessImpl.java:132)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021) ... 5 more
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)
The issue is that matlabcontrol on Windows and Linux expects 'matlab' to be understood due to the MATLAB directory being part of your PATH environment variable. This exception is indicating that is not the case. That's fine, you just need to explicitly set the location of where your MATLAB executable is. From the javadoc for setMatlabLocation(...):
Sets the location of the MATLAB executable or script that will launch MATLAB. If the value set cannot be successfully used to launch MATLAB, an exception will be thrown when attempting to create a proxy.
The absolute path to the MATLAB executable can be determined by running MATLAB. On OS X or Linux, evaluate [matlabroot '/bin/matlab'] in the Command Window. On Windows, evaluate [matlabroot '/bin/matlab.exe'] in the Command Window. The location provided does not have to be an absolute path so long as the operating system can resolve the path.
Windows
Locations relative to the following will be understood:
The current working directory
The Windows directory only (no subdirectories are searched)
The Windows\System32 directory
Directories listed in the PATH environment variable
App Paths defined in the registry with key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
By default on Windows, MATLAB places an App Path entry in the registry so that matlab can be used to launch MATLAB. If this property is not set, this App Path entry will be used.
OS X
Locations relative to the following will be understood:
The current working directory
Directories listed in the PATH environment variable
On OS X, MATLAB is installed in /Applications/ as an application bundle. If this property is not set, the executable inside of the application bundle will be used.
Linux
Locations relative to the following will be understood:
The current working directory
Directories listed in the PATH environment variable
During the installation process on Linux, MATLAB can create a symbolic link named matlab that can be used to launch MATLAB. If this property is not set, this symbolic link will be used.
Just to complement the answer, I had a similar problem (I am using Intellij IDEA and Matlab R2014a). Indeed the exact path of the program was missing from the Enviromental Variable Path.Some matlab paths can be found (or automatically written when installing matlab) like "C:\Program Files\MATLAB\MATLAB Runtime\" or "C:\Program Files\MATLAB\MATLAB Compiler\" but only the one that holds the .exe work, like "C:\Program Files\MATLAB\R2014a\bin". Yet, my program didn't work till I re-start the IDE. Keep that in mind.

Categories

Resources