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();
}
}
}
Related
I wanted to upgrade my eclipse version to the latest and it require me to upgrade also the java version.
After upgrade(java 15/eclipse 12-2020) I've notice that simple code that I had with freetts is not working with the new configuration.
I still have the old eclipse version that uses java 8, so I did the same steps in the old and the new version: create java project, add all the relevant jars files and set simple demo class.
In the old version it is working fine, while in the new it throws exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/VoiceManager
at demoPackage.TextSpecchClass.<init>(TextSpecchClass.java:13)
at demoPackage.TextSpecchClass.main(TextSpecchClass.java:8)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.VoiceManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
It seems basically that it cannot find the jars file but I'm not sure why, and if it related to the new eclipse version or the java upgrade.
*Also note that it in other sample I used external jar of sqllite and it worked, therefore it doesn't seems to happened with any jar, but something specific with the freetts
jars: (possible some are redundant...):
cmu_time_awb.jar
cmu_us_kal.jar
cmudict04.jar
cmulex.jar
cmutimelex.jar
en_us.jar
freetts.jar
freetts-jsapi10.jar
jsapi.jar
mbrola.jar
package demoPackage;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextSpecchClass {
public static void main(String[] args) {
new TextSpecchClass("Hello worlds");
}
public TextSpecchClass(String words) {
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Voice voice = VoiceManager.getInstance().getVoice("kevin16");
if (voice != null) {
voice.allocate();// Allocating Voice
try {
voice.setRate(190);// Setting the rate of the voice
voice.setPitch(150);// Setting the Pitch of the voice
voice.setVolume(3);// Setting the volume of the voice
voice.speak(words);// Calling speak() method
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
throw new IllegalStateException("Cannot find voice: kevin16");
}
}
}
Recent versions of Eclipse require at least a Java 11 JDK to run Eclipse, but you can compile/run the projects in Eclipse with older versions of the JDK. Ensure that you have both your Java 15 and Java 8 JDKs. Set Eclipse to run with the Java 15 JDK, and configure your project to use the "JavaSE-1.8" execution environment, and make sure that the Java 8 JDK is in the list of installed JDKs for that execution environment.
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?
I'm trying to set up JRI with Eclipse on a Windows 7 x64 system. I tried it once on my Laptop and it worked. Now on my Desktop it fails although everything of the R, rJava and JRI installation is exactly the same.
I set the JRI and R Paths correctly to:
C:\Program Files\R\R-2.15.1\library\rJava\jri;C:\Program Files\R\R-2.15.1\bin\x64
Also I set R_DOC_DIR etc in Eclipse.
Every time I try to run new Rengine(...); it fails without any error or exception. Debugging revealed an: <terminated, exit value: 10>C:\Program Files\Java\jre6\bin\javaw.exe (01.10.2012 18:00:31)
Is there anything I can try? It really bothers me that it works an my Laptop but not on my Workstation despite the same settings everywhere.
Edit: The code that is used to get the Rengine object.
public static Rengine getRengine(){
if (re == null) createRengine();
return re;
}
public static void createRengine(){
if (re!=null) return;
try{
if (!Rengine.versionCheck()) {
System.err.println("** Version mismatch **");
System.exit(1);
}
String[] arguments = {"--save"};
re=new Rengine(arguments, false, null);
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
}
catch (Exception e){
e.printStackTrace();
}
}
Edit: The last time i tried it i got an errormessage (creating of the REngine worked, this happened never before), R was missing a registryentry. After installing R 2.15.1 again it suddenly worked. Now after a restart it's the same like before. The program crashes at the creation of the REngine.
I was having the exact same problem. It turns out I had unchecked the box that asks to make a registry entry with the R version number. Once I let the installer run with that box checked, it seemed to work.
I would make sure your regedit looks like this:
Next up: getting this working in a portable way...
I am using R 3.2.2 and eclipse Mars on Windows 10 x64.
I faced the described issue today and tried around a bit. Finally, I found the root cause in the build path. Please check whether the following conditions are fulfilled:
1.) The following Java libraries from the JIRI folder on your hard disk shall be included as (user) libraries:
JIRI.jar
REngine.jar
JRIEngine.jar
2.) The native library jiri.dll is located in the subfolder "i386" for x86, whereas for x64 it is available in the subfolder "x64". The relevant one shall be added as separate native library location to the Java Build Path of the eclipse project. Otherwise, the file may not be considered as it is not located in the main JIRI folder.
Best regards
Philipp
i installed Jogl and included it in the build path of eclipse but it is under referenced libraries. Here is the program.
public class exceptionhandler
{ // open HelloWorld
public static void main(String[] args)
{ // open main
try
{ // open try
System.loadLibrary("jogl");
System.out.println("Hello World! (The native libraries are installed.)");
} // close try
catch (Exception e) // all try's need a catch
{ } // even if the catch does nothing
} // close main
} // close HelloWorld
I did not include the import because Eclipse didn't recognize it. So when i do run it i get this>
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl 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 exceptionhandler.main(exceptionhandler.java:8)
Are you sure you use the latest version of JOGL? Have you downloaded the JARs containing the native libraries too? Have you put them into the same directory than jogl-all.jar and gluegen-rt.jar?
Have you specified the path to jogl.dll in the Eclipse build-path settings?
See https://stackoverflow.com/a/958074/1216956 for instructions.
I trying to load SFmpq.dll via this code
static {
Native.setProtected(true);
System.setProperty("jna.library.path",
new File("lib").getAbsolutePath());
System.out.println(System.getProperty("jna.library.path"));
INSTANCE = (SFmpq) Native.loadLibrary("SFmpq", SFmpq.class);
}
It gets executed, Folder and File exist but I still get this error:
C:\Users\Frotty\Documents\NetBeansProjects\Optimizer\lib Exception in
thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Unable to
load library 'SFmpq': The specified module could not be found.
I gave the code and .dll a friend of mine who imported it into Eclipse and there it worked perfectly fine.
Can anyone spot my mistake or how do I import .dlls correctly?
You can get this error if you try to load a 32 bit library on a 64 bit system.
I've had success with using System.load(...) and System.loadLibrary(..) to load dlls