Java JNI trouble - java

I have the .java, .class, .cpp, .h files: http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html
After reading TotalFrickinRockstarFromMars's comment, I tried setting up classpath.
What's wrong?
Sample1.dll IS there.
Text version:
F:\workspace\JavaJNIProj\src>java Sample1
Exception in thread "main" java.lang.UnsatisfiedLinkError: F:\workspace\JavaJNIProj\src\Sample1.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Sample1.main(Sample1.java:10)

It looks like you miss some dependency DLLs. You can download DependencyWalker http://www.dependencywalker.com/
This supposed to help you to find it.

Related

java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path but natives are set

I understand that this question has been asked before, yet no matter how many solutions I try, I still get the following error:
Exception in thread "Game" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.system.Library.loadSystem(Library.java:97)
at org.lwjgl.system.Library.<clinit>(Library.java:48)
at org.lwjgl.system.MemoryAccess.<clinit>(MemoryAccess.java:22)
at org.lwjgl.system.Pointer.<clinit>(Pointer.java:22)
at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:594)
at Main.init(Main.java:27)
at Main.run(Main.java:39)
at java.lang.Thread.run(Unknown Source)
The problem is that I have properly set my Natives:
This is the location folder:
I have just downloaded LWJGL and would like help in order to make it work.
Thanks in advance!
It turns out that my anti-virus is deleting LWJGL.

java.lang.UnsatisfiedLinkError: no jpeg in java.library.path

We have a JavaWebStart application, which allows to scan images and write them to a file. All works fine but today I've got an exception from a customer, which I cannot understand.
java.lang.UnsatisfiedLinkError: no jpeg in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter$1.run(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi.createWriterInstance(Unknown Source)
at javax.imageio.spi.ImageWriterSpi.createWriterInstance(Unknown Source)
at javax.imageio.ImageIO$ImageWriterIterator.next(Unknown Source)
at javax.imageio.ImageIO$ImageWriterIterator.next(Unknown Source)
at de.eurodata.commons.scan.domain.ScanUtils.writeImageToFile(ScanUtils.java:81)
This exception is occured on Win7 x86. I've searched for this exception using Google but found only some irrelevant (Linux, Oracle 9i) or unanswered posts.
My question is: can I prevent this problem? Probably another pure Java jpeg plugin for ImageIO (if exists and stable)?

Error connecting Java to SQL Anywhere database

I am trying to connect a java program to a database. I have sajdbc4.jar in the build path and it worked before, but now I keep getting this error when I try to make the connection:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no dbjdbc12 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at sybase.jdbc4.sqlanywhere.IDriver.try_load(IDriver.java:455)
at sybase.jdbc4.sqlanywhere.IDriver.(IDriver.java:396)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)
at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
at java.util.ServiceLoader$1.next(Unknown Source)
at java.sql.DriverManager$2.run(Unknown Source)
at java.sql.DriverManager$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.sql.DriverManager.loadInitialDrivers(Unknown Source)
at java.sql.DriverManager.(Unknown Source)
at Main.main(Main.java:26)
Can someome please help me? Can't find anything abount this issue online.
For windows find this file in your computer:
dbjdbc12.dll
For linux find this file:
libdbjdbc12.so
Put the location of this file on the java.library.path either with a command line option:
java -Djava.library.path=DIRECTORYWITHDLL ...
or using System.setProperty in your code:
System.setProperty("java.library.path","DIRECTORYWITHDLL");
For Linux, you need to add the dbjdbc12.so to java.library.path using:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/some/path/that/contain/dbjdbc12.so
this is the same for dbjdbc16 also.
Since, sybase.jdbc4 driver need this file. Please refer- https://blogs.sap.com/2014/05/02/connecting-to-sql-anywhere-using-jdbc-2/#:~:text=jar%20is%20in%20the%20classpath,Connection%20con%20%3D%20DriverManager.
Similarly, for windows add dbjdbc12.dll file.
For SQL Anywhere 17 libdbjdbc17.so was not suffiecient, it was then complaning about the next file:
failed: java.lang.UnsatisfiedLinkError: /usr/local/tomcat/native-jni-lib/libdbjdbc17.so: libdbtasks17_r.so: cannot open shared object file: No such file or directory
So I ended up adding all files from the lib64 folder from the Database client (after I installed it on some other linux machine) to my tomcat lib path and it worked.

Java - Library path error

I'm trying to start my java game but I have some troubles with the java command line:
Here is what I type:
C:\>java -Djava.library.path=%cd%\lib -jar game.jar
And here is what I got:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at com.game.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I can start my game with Eclipse (With Run as Java Application) but after the menu I got the following error:
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
at org.lwjgl.Sys.loadLibrary(Sys.java:81)
at org.lwjgl.Sys.<clinit>(Sys.java:98)
at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
at com.game.displaygui.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
lwjgl.jar has been put into the folder \lib.
Could you explain me with I got that?
Thanks.
This because lwjgl library is made by two components:
the .jar file which contains Java code
and the native binary library (which can be .so or .dll or .dylib according to your OS)
The first error you are getting is because you are setting the library path, that should contain the native library, but it does contain the .jar. So you get a java.lang.NoClassDefFoundError because you should set either the library path to the folder that contains native library, either the classpath to contain the real lwjgl.jar file.
The second error that you get with Eclipse is a successive step: your classpath contains the jar library but it is not able to find the native library attached to it, you can fix it in the following way:
You should specify explicitly which lib files to include (seperated by ;) :
-cp %cd%\lib\lwjdl.jar;%cd%\lib\<another-lib>.jar
Don't be tempted to use the wildcard * as it will cause more harm than good (from previous experience :))
You use the java.library.path option to specify the location of native libraries to load. In the location pointed to by that option you would place all dll or .so files required by LWJGL. On the other hand, you need to make sure that all required JAR files are on your classpath, via the -classpath option. Currently, you have your JAR files in the wrong directory.
In Eclipse, if you using maven.
Add the following to the project "Run" : "VM options" .
-Djava.library.path=yourpath/youproject/java/target/natives

How do I add external libraries to java.library.path in Eclipse?

My first time playing around with JOGL, and I get this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.gluegen.runtime.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:117)
at com.jogamp.gluegen.runtime.NativeLibLoader.access$000(NativeLibLoader.java:51)
at com.jogamp.gluegen.runtime.NativeLibLoader$1.run(NativeLibLoader.java:70)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.gluegen.runtime.NativeLibLoader.loadGlueGenRT(NativeLibLoader.java:68)
at com.jogamp.common.jvm.JVMUtil.<clinit>(JVMUtil.java:56)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:1145)
at tut.Main.main(Main.java:10)
I looked around and found nothing on how to add gluegen-rt or anything else to java.library.path.
See the answer at "How to set the java.library.path from Eclipse". Basically, there is a project configuration for "Native library location".

Categories