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)
Related
I wanted to connect Java and Swi Prolog together using JPL.
When I added the library to my project on Intellij the code compiled and when I tried to run a query I got a runtime error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path: [C:\Program Files\Java\jdk-12\bin, C:\WINDOWS\Sun\Java\bin, C:\WINDOWS\system32, C:\WINDOWS, c:\swipl\bin, ${env_var:PATH}, .]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
at java.base/java.lang.System.loadLibrary(System.java:1902)
at org.jpl7.JPL.loadNativeLibrary(JPL.java:114)
at org.jpl7.fli.Prolog.<clinit>(Prolog.java:71)
at org.jpl7.Query.open(Query.java:369)
at org.jpl7.Term.textToTerm(Term.java:155)
at org.jpl7.Query.<init>(Query.java:169)
at Main.main(Main.java:7)
I have the swi prolog 64 bit.
I've tried uninstalling it and use the 32 bit but it did not work.
What I did so far:
I added SWI_HOME_DIR to my Environment Variables.
I also added the swi path to Path variable.
I added the jpl library to my project (and it added it successfully).
The code I was trying to run:
import org.jpl7.*;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Query q = new Query("true");
q.hasSolution();
Map<String,Term>[] res = q.allSolutions();
for (int i = 0; i < res.length; i++) {
System.out.println(res[i]);
}
}
}
So, is jpl.dll in any of the listed directories:
C:\Program Files\Java\jdk-12\bin ... probably not
C:\WINDOWS\Sun\Java\bin ... probably not
C:\WINDOWS\system32 ... probably not
C:\WINDOWS ... probably not
c:\swipl\bin ... apparently yes as c:\swipl\bin\jpl.dll exists?
${env_var:PATH} ... apparently not
Try the suggestion from this question in your Java program:
File nativeFile = new File(filename + ".dll");
if (!nativeFile.exists())
System.exit(1);
System.load(nativeFile);
Note that just having jpl.jar is not enough. One needs the jpl.dll file, too. jpl.jar is good for the Java part of the Java-Prolog bridge, but to be able to call a non-JVM compilate, we need to get into system-level details, Hence the dll file.
See troubleshooting tips here: JPL Deploying for users - on Windows
From the above page:
If the Java examples complain that
The dynamic link library libpl.dll could not be found in the specified path
or
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\paul\bin\jpl.dll: Can't find dependent libraries
then there is no SWI-Prolog library libpl.dll in any folder on your
PATH: you should have a PATH entry such as C:\Program Files\pl\bin.
The libpl.dll should contain the code for SWI-Prolog itself.
I would try to execute an example script based on Aparapi, on MAC OS. I'm using the last version of Eclipse, but when I execute DeviceInfo example to get all the available devices:
public class DeviceInfo {
public static void main(String[] args) {
KernelPreferences preferences = KernelManager.instance().getDefaultPreferences();
System.out.println("-- Devices in preferred order --");
for (Device device : preferences.getPreferredDevices(null)) {
System.out.println(device);
}
}
}
it generates the
java.lang.UnsatisfiedLinkError: com.amd.aparapi.OpenCLJNI.getPlatforms()Ljava/util/List"
Is there someone who can help me?
build the native assembly for Mac (x86_64) and add it into jniLibs; here's the source code.
java.lang.UnsatisfiedLinkError generally means, that it cannot find the native assembly.
Despite macOS Mojave 10.14.4 don't support directly OpenCL, I've executed Aparapi Framework.
I founded that the problem is the Aparapi Library. In particular, to resolve generated error I followed these steps:
Download this repository https://github.com/aparapi/aparapi for AMD Graphic Cards
Open the directory "com.amd.aparapi" and from terminal execute
ant -f build.xml
This command generates .jar file of this library
Add the generate jar to the project's classpath in Eclipse
Add the specific Aparapi library for your OS in:
<your-workspace-path>/<your-project>/src/main/resources/osx/
Before to execute the code, add the VM argument in "Run Configuration"
-Djava.library.path=<your-workspace-path>/<your-project>/src/main/resources/osx/
Execute your script!
I am working on Calling matlab function in java code by using Java Matlab Engine API in Eclipse.
I have written very simple program but its giving me runtime error.
I have written this code:
import com.mathworks.engine.*;
import com.mathworks.*;
public class Matlab_main {
public static void main(String[] args) throws Exception
{
MatlabEngine eng = MatlabEngine.startMatlab();
eng.evalAsync("disp('hello world')");
eng.close();
} }
I have done the following steps:
I have added engine.jar file in its library build path .
I have also set its java.library.path = "C:\Program Files\MATLAB\R2013a \bin\win64" by going into its Native Library settings.
I have also added this entry C:\Program Files\MATLAB\R2013a\bin\win64 to PATH environment variables
But its giving me error that System cannot Load Native Library mvm.dll
This dll is present in this directory C:\Program Files\MATLAB\R2013a\bin\win64,but eclipse is not finding that.
I am totally stuck, Please kindly help me
So, I am trying to use my ruby scripts inside my java code with the help of JRuby. But there is a problem, eclipse is not being able to use the gems I have installed. For testing purposes, I've been trying to run a piece of code that requires the "nokogiri" ruby gem, which I have installed. When I try to run the java code, here's what I get:
LoadError: no such file to load -- nokogiri
require at org/jruby/RubyKernel.java:939
<top> at /home/amng/workspace/scripts/xx/x/getMSPatches:4
Exception in thread "main" org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- nokogiri
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1307)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1352)
at jobs.Teste.run(Teste.java:17)
at jobs.Teste.main(Teste.java:11)
Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- nokogiri
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:939)
at RUBY.(/home/amng/workspace/scripts/myPrecious/MSPatches/getMSPatches:4)
I downloaded the jruby.jar from the website and added to the build path of the project. I also pointed the eclipse to the JRuby binary using the Dynamic Languages Toolkit (DLTK) plugin. What do I have to do to make sure that eclipse can use the gems I have installed?
Edit: My java code:
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.PathType;
public class Main {
public static void main(String[] args) {
ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
Object result = ruby.runScriptlet(PathType.ABSOLUTE, "/home/amng/workspace/scripts/myPrecious/MSPatches/getMSPatches");
System.out.println(result);
}
}
The first two lines of my (working) ruby code (getMSPatches) are:
# encoding: UTF-8
require 'nokogiri'
Try setting the jruby home directory
ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
ruby.setHomeDirectory("/jruby-9.0.5.0");
This solved the issue for me.
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