i have a java program that works with jna and loads a dll. On my develop computer the program runs without problems. But when i run the program on a different pc i get the error that the program cant find the dependet dlls. But my dll depends only on one dll an this dll is inside the same folder.
I run the program as a jar on Windows 7. Dependency walker shows on both pc the same dependecies.
I dont know what the problem or the difference between those computers is.
Why cant the program load the dll?
Error Message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\THZ-standalone\Dlls\BladeTileLocator.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.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at de.thz.cameracontrol.utils.Utils.loadLibrary(Utils.java:169)
at de.thz.cameracontrol.server.Server.<init>(Server.java:124)
at de.thz.cameracontrol.server.Server.main(Server.java:165)
I call the program with java -jar Program.jar.
The dlls are saved in a folder (this folder is in the same folder as the java program).
Here is the method for the libray loading:
public static Object loadLibrary(String libraryName, Class<?> clazz) {
final String userDir = System.getProperty("user.dir");
final String filePathToUse = userDir + "\\" + DLL_PATH;
System.setProperty("jna.platform.library.path", filePathToUse);
System.load(filePathToUse + libraryName + ".dll");
return Native.loadLibrary(libraryName, clazz);
// return Native.loadLibrary(libraryName, clazz);
}
I use the statement System.load(filePathToUse + libraryName + ".dll"); for better error messages.
The origin of the problem was a wrong name for the JNA library path system property. The right name is jna.library.path.
1) Start your application with -Djna.debug_load=true -Djna.debug_load.jna=true to get some information where the JNA library is looking for the DLL.
2) Shouldn't it be rather jna.library.path instead of jna.platform.library.path.3) Maybe you are mixing 32bit/64bit DLL/JVM?
Related
I am trying to get J3D to work in Eclipse and have read forum after forum but can't seem to fix my problem. I am using ubuntu 11.10
I have done this:
0) unzipped j3d-1_5_2-linux-i586 in home/j3d directory then added i386 folder to usr/lib/jvm/java-6-openjdkjre/lib/i386
1) Window--> Preferences--> User Libraries --> New and added the three .jar files (j3dcore.jar, j3dutils.jar, vecmath.core)
2) Added a native library location to point to usr/lib/jvm/java-6-openjdkjre/lib/i386 where the .so files are
Some sources say try adding the .jar files to your Classpath Variable which didn't fix the problem for me.
I keep getting
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libj3dcore-ogl.so: /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libj3dcore-ogl.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1667)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.(VirtualUniverse.java:299)
at Hello3d.(Hello3d.java:13)
at Hello3d.main(Hello3d.java:27)
I had the same problems. Most tutorials tell you to assign an new library, but i mixed the Java3D files with the JDK files and re installed eclipse. If this doesn't work use net Beans.
I want to use this jar file (http://sourceforge.net/projects/uirt-j/) in a personal project. Currently, I've been using Eclipse and tried to Project > Java Build Path > Add External JARs to import that jar.
After importing it, I can see all classes from that package listed in Eclipse, however, this jar also contains two win32 dll files, needed to communicate to the device. I've tried to add them to System32 dir, but no luck. When that code runs, it throws the following exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
C:\Windows\System32\util_USBUIRT.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 util.USBUIRT.<clinit>(USBUIRT.java:269)
at Uirt.main(Uirt.java:6)
Using dependence walker, I can see that all the dlls are correctly linked can be imported.
This is the code snippet I'm trying to run:
import util.USBUIRT;
public class Uirt {
public static void main(String[] args) {
String code = "0000";
try {
USBUIRT.transmitIR(code, 2, 3, 2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
If that JAR file is executed standalone, it works fine. My current setup runs under Windows 7 64bits.
The dlls in the mentioned jar are 32 bit. The environment is Win7 x64. I assume the JVM is 32 bit otherwise there would be another error, ie: Can't load IA 32-bit .dll on a AMD 64-bit platform or similar.
Try copying the dlls into C:\Windows\SysWOW64 rather than C:\Windows\System32. 32 bits dlls should go into C:\Windows\SysWOW64. It worked for me, although I got util.USBUIRT$NotInitializedException which is probably the indication the libraries were loaded properly.
File System Redirector article may shed some light on SysWOW64 vs System32.
EDIT: tweaking java.library.path
You may also go with a solution mentioned in comments, for example, copy dlls into C:\tmp and run with argument:
-Djava.library.path="C:\tmp;${env_var:PATH}"
But since there is a dependency between the two dlls, C:\tmp must be on PATH. Otherwise there is still UnsatisfiedLinkError. Manually loading uuirtdrv.dll should help, ie:
import util.USBUIRT;
public class Uirt {
static {
System.loadLibrary("uuirtdrv");
}
public static void main(String[] args) {
String code = "0000";
try {
USBUIRT.transmitIR(code, 2, 3, 2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I'm developing a Grails web application and I need to use a JNI native library to access some specific hardware. For a simple Java application (see below) it works fine. To do this I just have to add the JAR to the Java build path and specify the "Native library location" (I use SpringSource Tool Suite on Windows7).
Working example:
import conceptacid.nativedriver.Driver;
public class Main {
public static void main(String[] args) {
System.out.println("starting...");
System.loadLibrary("AudioCardDriver");
Driver driver = Driver.instance();
String driverDescription = driver.getDriverDescription();
System.out.println( "Native application driver: " + driverDescription);
}
}
However, when I try to add it into my Grails application it fails:
Bootstrap.groovy:
import conceptacid.nativedriver.Driver;
class BootStrap {
def init = { servletContext ->
System.loadLibrary("AudioCardDriver");
Driver driver = Driver.instance();
String driverDescription = driver.getDriverDescription();
System.out.println( "Native application driver: " + driverDescription);
}
def destroy = {
}
}
the first line System.loadLibrary("AudioCardDriver"); is executed silently without any exception but the next line where I try to use my native code Driver driver = Driver.instance(); fails:
Running script C:\grails\scripts\RunApp.groovy
Environment set to development
[groovyc] Compiling 1 source file to D:\Projects3\mbr\target\classes
[delete] Deleting directory C:\Users\VShmyrev\.grails\1.3.7\projects\mbr\tomcat
Running Grails application..
2012-02-24 15:19:49,690 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: java.lang.UnsatisfiedLinkError: conceptacid.nativedriver.AudioCardDriverJNI.swig_module_init()V
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.UnsatisfiedLinkError: conceptacid.nativedriver.AudioCardDriverJNI.swig_module_init()V
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:251)
...
Caused by: java.lang.UnsatisfiedLinkError: conceptacid.nativedriver.AudioCardDriverJNI.swig_module_init()V
at conceptacid.nativedriver.AudioCardDriverJNI.swig_module_init(Native Method)
at conceptacid.nativedriver.AudioCardDriverJNI.<clinit>(AudioCardDriverJNI.java:70)
at conceptacid.nativedriver.Driver.instance(Driver.java:35)
at conceptacid.nativedriver.Driver$instance.call(Unknown Source)
at BootStrap$_closure1.doCall(BootStrap.groovy:7)
... 26 more
Application context shutting down...
I'm sure I put the DLL into a directory which is in my system PATH but it doesn't help.
What is the right way to use a native library in Grails application both in a development environment and in production?
Your DLL needs to be on a path specified in the Java system property java.library.path. On Windows the PATH environment variable and Linux the LD_LIBRARY_PATH environment variable are added to this system property. You can try logging the java.library.path system property to see if Java is looking in the right place for your DLL.
I'm guessing that the native library is being loaded multiple times in different classloaders, so forking a new JVM when running the app might help.
My Java program fails with the following error on Windows.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no XSvcSocket 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)
I tried different things like
adding the location of DLL to system's path env variable
setting location of DLL explicitly in the program as below
String libpath = System.getProperty("java.library.path");
libpath = "C:\\extlibs;" + libpath;
System.setProperty("java.library.path", libpath);
libpath = System.getProperty("java.library.path");
java.library.path I get see is shown below.
"Lib Path: C:\extlibs;C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows"
The DLL in question is available in "C:\extlibs". Couple of observation are that when I place the DLL into "C:\Program Files\Java\jre6\bin", my program doesn't crib about the DLL (i.e it loads it) but I have to take care of many other DLLs too.
Can anyone shed some light on this behavior? by the way I am also not able to figure out from where eclipse is picking C:\Program Files\Java\jre6\bin and adding to java.library.path? it's not part of system's path environment variable.
The correct way to add native libraries in eclipse is as shown below. Go to Properties/Java Build Path/Libraries/Expand the jar file for which you want to add the native library/Select Native Library location/Click Edit/Add the DLL
I have written a code that requires 2 dll's at runtime.I have those dll files in C:\Program Files\Java\jdk1.6.0_01\jre\bin.
I have set the environment variable PATH accordingly.
It compiled successfully and then while running it gives the following error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at teamdev.jxcapture.Capture.captureActiveWindow(Unknown Source)
at ppb.activewindow.execute(activewindow.java:24)
at ppb.activewindow.main(activewindow.java:68)
Caused by: com.jniwrapper.LibraryNotFoundException: Cannot find JNIWrapper nativ
e library (jniwrap.dll) in java.library.path: C:\Program Files\Java\jdk1.6.0_01\
jre\bin\jniwrap.dll
Could anybody please help me to resolve this problem?
The value of java.library.path should be the directory containing the DLLs, not the filename of the DLLs themselves. It looks like your java.library.path is set to
C:\Program Files\Java\jdk1.6.0_01\jre\bin\jniwrap.dll
instead of
C:\Program Files\Java\jdk1.6.0_01\jre\bin
It looks like the DLL is not being found on the Java Library Path. See this - http://www.inonit.com/cygwin/jni/helloWorld/load.html
Try moving JDK to a path without spaces.