How to solve this JNA issue? - java

I have application which use JNA and gets the audio and video. It works in my Linux box. But when i am testing it in Windows. It just never working. Because i am still learning, i will appreciate your suggestion how to fix it, i already spent few days and weeks only to work it out, but just dont get this why JAVA does not work simply, its a cross platform. Why should it require again System path or etc configuration.
I am totally lost now, why it works in Linux and it does not work in Windows XP ? How can i run it then ?
Inside the lib direcotry i have my JNA and Audio libraries.
C:\Documents and Settings\test\Desktop\test>dir
Volume in drive C has no label.
Volume Serial Number is 680F-0963
Directory of C:\Documents and Settings\test\Desktop\test
19/12/2010 22:09 <DIR> .
19/12/2010 22:09 <DIR> ..
19/12/2010 22:09 51.791 Audio.jar
19/12/2010 22:09 <DIR> lib
1 File(s) 51.791 bytes
3 Dir(s) 487.002.112 bytes free
Now trying to run Audio.jar, gets Fail 1:
C:\Documents and Settings\test\Desktop\test>java -Djava.library.path=~/jni -jar
Audio.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load librar
y gstreamer-0.10
at org.gstreamer.lowlevel.GNative.loadWin32Library(GNative.java:83)
at org.gstreamer.lowlevel.GNative.loadLibrary(GNative.java:43)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:42)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:39)
at org.gstreamer.Gst.<clinit>(Gst.java:59)
at video.MyVideo.simpletest(MyVideo.java:31)
at sipphone.MainApplet.run(MainApplet.java:58)
at sipphone.MainApplet.main(MainApplet.java:43)
Fail 2:
C:\Documents and Settings\test\Desktop\test>java -Djna.library.path=. -jar Audio
.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load librar
y gstreamer-0.10
at org.gstreamer.lowlevel.GNative.loadWin32Library(GNative.java:83)
at org.gstreamer.lowlevel.GNative.loadLibrary(GNative.java:43)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:42)
at org.gstreamer.lowlevel.GstNative.load(GstNative.java:39)
at org.gstreamer.Gst.<clinit>(Gst.java:59)
at video.MyVideo.simpletest(MyVideo.java:31)
at sipphone.MainApplet.run(MainApplet.java:58)
at sipphone.MainApplet.main(MainApplet.java:43)

You'll need to have the DLL installed, or at least in your JNA library path as others have pointed out.
It does add an extra dependency on Windows. It would be an extra dependency on Linux but gstreamer is preinstalled by your distribution. I ran into this same problem when I was making something to use a USB port from Java.
The only solution I know of to avoid the DLL would be to have a second version of the code you could call on Windows that would only use Win32 stuff (i.e. stuff that ships with Windows) but that would be a very large undertaking.

trying to run mediarenderer from cling package, I had the same error on windows xp.
i got the right libgstreamer-0.10.so from package GStreamer-WinBuilds-GPL-x86-Beta04-0.10.7.msi found in https://code.google.com/archive/p/ossbuild/downloads
once installed (environment variables PATH (for dependencies) and OSSBUILD_GSTREAMER_DIR set),
in a prompt, I was finally able to run mediarenderer using the following syntax to introduce lib's path :
Z:\Downloads\cling-distribution-2.1.0\cling-distribution-2.1.0\mediarenderer\target>java -Djna.library.path="C:\Program Files\OSSBuild\GStreamer\v0.10.7\bin" -jar cling-mediarenderer-2.1.0-standalone.jar
hope this helps as a starting point !

For Fail 1: I don't believe that the ~/ syntax will work on Windows. Try %HOME%\ instead. The tilde expansion happens in Bash, so things are a bit different in Windows.
For Fail 2: It doesn't look like the .dll is in your test directory, and you're setting the jna.library.path to ..
If the .dll's are in your lib directory, then shouldn't the paths be set to that directory, instead of ~/jni and .?

Related

Cannot load the JNotify native library (no jnotify in java.library.path)

When I try to run any play project, I'm getting the following warning, and it seems to be making my projects run considerably slower than normal:
Cannot load the JNotify native library (no jnotify in java.library.path)
Play will check file changes for each request, so expect degraded reloading performance.
I found this question, that seems to have solved the issue for Windows users, but I haven't found a solution for Linux machines
I tried copying the .jar and .so downloaded from here into /usr/lib/jvm/jdk1.8.0_212/bin/ with no success
Also, I noticed that in my play directory (~/play/repository/local/net.contentobjects.jnotify/jnotify/0.94/jars) there is a jnotify.jar, so I'm not sure why it is not using that one
I'm using Play v2.2.4, on Ubuntu 20.04 64 bits
After extracting the .so from jnotify.jar, the output of the ldd libjnotify.so command was:
linux-vdso.so.1 (0x00007ffd4c3cd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f94bbed5000)
/lib64/ld-linux-x86-64.so.2 (0x00007f94bc2df000)
It doesn't seem to list any unresolved libraries (though I'm not sure how to interpret that output). libc.so.6 and ld-linux-x86-64.so.2 exist in the directories listed, and I'm not sure where it looks for linux-vdso.so.1
Any help is appreciated!
I'll describe how it was solved for the future generations:
First, download JNotify here and unzip it
Then type java -XshowSettings:properties into the terminal, and check the java.library.path property.
In my case, the first path listed here was /usr/java/packages/lib/amd64
Finally, move the unzipped file 64-bit Linux/libjnotify.so to the directory in java.library.path (in my case, /usr/java/packages/lib/amd64)
After restarting play, it worked
Thanks again #cbley!

Error when starting Datomic shell: java.lang.NoClassDefFoundError: jline/ConsoleRunner

I followed the instructions on the Datomic site: http://docs.datomic.com/getting-started.html, but I'm getting this error when trying to start up the datomic shell prompt. I'm using a windows machine. Any suggestions? I tried the same thing on my linux box and did not get this error.
Edit: moved to a different windows machine and it's working. If I have time to troubleshoot this problem and I find a solution I'll report back
I noticed that you cannot run the shell.cmd from within the bin directory, you need to call it with bin\shell.cmd from the parent directory... hope that helps.
In case you are using cygwin/bash and call bin/shell :
The java runtime on windows does not understand classpath with a ":"
but this is what you get from bin/classpath.
Either correct this or use DOS-CMD shell and call bin/shell.cmd inside.
Regards
Some tips for running datomic on Windows (7 at least):
Do not download datomic into Program Files. On startup, it creates logging directories and temp files into its own directories, so unless you run the command prompt as Administrator, you're gonna have screens full of Unable to write to file... errors.
You need to run datomic as such (assuming you extracted the download to C:)
c:\datomic-free-0.x.xxxx>bin\shell.cmd
Note the backslash. Tripped me up forever coming from *nix world.
After that, return to your regularly scheduled datomic tutorials.

java.lang.UnsatisfiedLinkError: Java cannot find my dll's?

I am developing a program that calls R functions from Java using JRI/rJava. I was coding the program in NetBeans on another machine, which was working fine (i.e. able to run the code). I have since then moved to another machine and have been running into problems.
The exact error message I am seeing is this:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: E:\R\R-2.13.1\library\rJava\jri\jri.dll: The specified path is invalid
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at com.rjava.test.rtest.main(rtest.java:64)
Java Result: 1
I have read the FAQs for JRI/rJava, and have been scouring the internet for fixes, but have made no progress. Here is what I have done so far:
Created an environment variable called R_HOME: "E:\R\R-2.13.1"
Added "%R_HOME%\bin\x64" to the PATH environment variable
Added "%R_HOME%\library\rJava\JRI" to the PATH environment variable (this is where jri.dll is located)
Set the required jar files as compile time libraries (JRI.jar, JRIEngine.jar, REngine.jar) in NetBeans
set the following VM options in NetBeans: : -Djava.library.path=E:\R\R-2.13.1\library\rJava\jri (This is where jri.dll is located)
I have restarted my computer to make sure that the changes stick.
To make sure I configured things correctly, I ran the following in the command line:
java -cp E:\R\R-2.13.1\library\rJava\jri\JRI.jar;E:\R\R-2.13.1\library\rJava\jri\examples rtest
And the example java files ran fine. I'm beginning to think my new machine just hates me.
The message indicates that it the path E:\R\R-2.13.1\library\rJava\jri\jri.dll is invalid. Are you sure that path exists? Also, is E a mapped drive that is mapped to a path that has spaces in it? I'm not sure if the spaces are the issue, but it eliminates one issue. I would try just putting the dll in C:\ or somewhere very simple and seeing if it can find it there as a simple test.
Also verify that the -Djava.library.path is being passed as you think it is (you can check that with visualvm or jconsole).
You could try this:
-Djava.library.path=E:\R\R-2.13.1\library\rJava\jri -cp E:\R\R-2.13.1\library
\rJava\jri;E:\R\R-2.13.1\library\rJava\jri\JRI.jar;E:\R\R-2.13.1
\library\rJava\jri\examples
The reason I say this is that, perhaps the .dll also needs to be in the classpath as well as the library path in order for the classloader to load it? Its probably not true, but worth trying. Also is "rJava" correct? Other than that, it looks to me like your doing it right.
To locate JRI installed with rJava, use system.file("jri",package="rJava") in R.
set that path to your path (environment variables in windows),
restart your netbeans. and try to run your program again

Java - java.library.path problem on Linux

I am able to run a java program with some dependencies from cmd line on my mac, but when I try to run it on a linux SUSE 11 box I have it comes back with:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no myNativeLib in java.library.path
This is the cmd line I am running:
java -Djava.library.path=../lib -cp ../jar/a-jar.jar:. MyMainClass
Any help appreciated!
I would recommend to use absolute path for java.library.path. At least you eliminate possible problems with relative path resolution.
Also, just to confirm, you do have Linux library in the lib, right? Mac one will not work.
I'm going go out on a limb and assume(at the risk of a bunch of downvotes) that you are trying to use oracle's native database driver.
If it is indeed a database driver that you are using, you can bail on the native version and simply include the .jar thin client on your classpath by using the -cp extension. This may require some code changes such that you are not attempting to invoke the native driver.
If you are hell bent on using a native driver or you need to because the code relies on it. you need to make sure that the java.library.path variable is set to a directory containing the binary driver files(typically denoted with a .so extension).
Also make sure these driver files(since they are native binary) have been compiled for your distribution of linux and not just conveniently copied from the mac install.
If you are not doing any of these things feel free to ignore everything I've said.

Check if a program is installed on a linux machine from a java applet

Hi I need to be able to check if a certain software is installed on the clients computer and where, in order to launch it. I found the following three posts as to how to do so on Windows and Mac but I can't seem to figure it out for Linux as there is no registry. Does any one know how this can be done on Linux?
Similar posts for Windows and Mac:
Can a Java applet open a "select directory" and write to a filesystem via JavaScript interaction?
read/write to Windows Registry using Java
How can I see the software installed in a Mac OS using a java application?
any help would be greatly appreciated :)
Assuming your security context allows it, you could call out to which.
$ which java
/usr/bin/java
which will output nothing if the program is not found.
Use the
which file
command to find out if the software is installed in the path. If that comes up with nothing then you could do a
find ./ -name "file"
Also check their local bin or .bin if its not included in the path.
Well, basically every binary installed on Linux is in the PATH (environment variable), so if you can find it there, it's there.
There may also be software that installs into other paths, but in this case the user would need to point them out. It is a very uncommon case to have an application in a seperate path and not adding that one to PATH.

Categories