java.lang.UnsatisfiedLinkError when i load a jar . - java

I ' m programming with JSE and i'm loading a jar (that i do ) with another java program .
The problem is in classLoader of java virtual machine i think .
i said that beacuse i tried to exec the file jar with java -jar "file.jar" and it runs .
I'm using xubuntu with eclipse.
In eclipse, i have 2 project that respectively are the first software that loads jar and the jar software .
To export the jar file i use the wizard "Export -> jar ecc...."
How can i resolve this problem?
Exception in thread "main" java.lang.UnsatisfiedLinkError: /media/sda4/so_project/proj/example/first.jar: /media/sda4/so_project/proj/example/first.jar: invalid ELF header (Possible cause: endianness mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at it.unicam.project.Binterpreter.getClassHandle(Binterpreter.java:170)
at it.unicam.project.Binterpreter.(Binterpreter.java:100)
at it.unicam.project.Test.main(Test.java:12)

That's because you're running a 32bit JVM on a 64bit platform

Related

Export a runnable JAR and include .so native library

I'm writing a java application (on Linux OS) which accesses the webcam and display a video on a JPanel. I'm using openCV libraries in order to obtain it (also because I would like to add some image processing code).
I followed this guide to compile the openCV library for Java
and the only way I could make it work was by creating an user library linked to the folder where I have the corresponding jar file.
(I tried to directly import the jar file but I have some runtime exception, so I gave up).
This is my situation.
Now I have a working application (if I execute it from within Eclipse), and I want to export it as a single jar (or something executable outside Eclipse). I tried to achieve this by selecting these options.
The problem is that now I want test if the jar works by executing the following command from terminal (where Untitled.jar is the name of the exported code):
java -jar Untitled.jar
but I receive this error (I bolded the main problem):
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java331 in
java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at
myRefreshTest.Main.main(Main.java:8)
opencv_java331 is the name of the .so library generated after building openCV for Java (opencv_java331.so)
I tried several way to export my program, also by selecting the 3rd option in the Eclipse export popup ("Copy required libraries into sub-folder next to the generated JAR) and then executing
java -cp Untitled_lib/opencv-331.jar -jar Untitled.jar
but terminal returns this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
opencv_java331 in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at
myRefreshTest.Main.main(Main.java:8)
So, the problem is clear, it can't find the openCV .so library.
I tried to use also option -Djava.library.path but it is not working (or at least I'm not using it properly)
I'm not a Java expert and I cannot understand how to fix this problem. Does anyone know how to fix this issue?

Including libraries generating jar and executing with java -jar on Intellij

I've been trying to execute a jar file through command line but I'm still getting an exception that I'm missing a library even though it was properly added as it's shown here. The library that I'm trying to run my code with is the opencv's lib. I'm able to run my app from intellij and generate a jar artifact that I can see the jar grows in size when I add the opencv lib but when I try to run the app from the command line with "java -jar Test.jar" I get the message that I'm missing the opencv library.
rinaldi#rinaldi-work:~/Projects/Test/out/artifacts/Test_jar$ java -jar Test.jar Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at HelloWorld.<clinit>(HelloWorld.java:14)
at Main.main(Main.java:4)
I've also tried to run the app adding the path to the opencv's library:
:~/Projects/Test/out/production/Test$ java -cp .:~/Sources/opencv-master/build/bin/opencv-310.jar Main
And another attempt because opencv needs not only it's jar but also the /opencv-master/build/lib/ directory:
:~/Projects/Test/src$ java -cp :/home/rinaldi/Sources/opencv-master/build/bin/opencv-310.jar:/home/rinaldi/Sources/opencv-master/build/lib/ Main
Below are the images from intellij's configuration.
I had to add the library this way:
java -jar -Djava.library.path=/home/rinaldi/Sources/opencv-master/build/lib test.jar
Hope this helps someone.

Error while running my jar outside of the ide using command line and external lib

I got a programm which is working on my ide (Eclipse Luna Service Release 2 (4.4.2)). Now i want to execute it without Eclipse to be able to run it on others computer.
I exported it from eclipse using export projet into a jar file, a specified this manifest:
Manifest-Version: 1.0
Main-class: RecupPhoto
Class-path: opencv-300.jar
Both files, RecupPhoto.jar and opencv-300.jar are in the same folder, i already checked the java path, the jre and jdk.
My problem is when i execute:
java -jar RecupPhoto.jar
with a .bat file inside the jar folder i got this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java300 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 Ihm.<init>(Ihm.java:89)
at RecupPhoto.main(RecupPhoto.java:10)
I'm not expert on errors etc but i understand that there is an error with "opencv_java300", but i don't understand this error because i didn't get this import with a "java" in the middle of the name.
Here is the loadlibrary from the error, in case it could help:
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
(core is a package from opencv library).
So any idea/help will be welcome! (and sorry for my poor english)
I was missing the path to dll in my bat file,
new call is:
java "-Djava.library.path="C:\opencv\build\java\x64 -jar RecupPhoto.jar

Compiling and running in java. Giving me errors

compiled my project in netbeans IDE and when I run the jar nothing happens just gives me a error occured while trying to run it. I think I found the problem just not sure how to fix it. Help please!
This is what happens when I check the jar in CMD
C:\Users\Mac\Desktop>java -jar dist\pong.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.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:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at mw.Main.initDisplay(Main.java:36)
at mw.Main.main(Main.java:25)
C:\Users\Mac\Desktop>
When I check the manifest file it's pretty much empty:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
when I check the jar in CMD C:\Users\Mac\Desktop>java -jar dist\pong.jar
You need to use the -cp switch while running the jar using the java command.
Documentation
You can easily google to find more examples on how does -cp works.
You need to create a library and add a reference to it in your project
See Setting Up LWJGL with Netbeans
At a guess I'd say you are missing step 5 from Setting Up a Project to Use LWJGL in NetBeans
Finally, you need to tell NetBeans where the Native Libraries (i.e, DLL, JNILIB, DYLIB, SO files) are for your system so that the natives are linked when running.
Select the Run category and then type the following into the VM Options, replacing what is in bold to suit your system:
-Djava.library.path=<lwjgl-X.X path>/native/<linux|macosx|solaris|windows>
Update: Didn't realise you were doing it from the command prompt. You say you are running
java -jar dist\pong.jar
You need to add the -D option so something like this:
java -Djava.library.path=<lwjgl-X.X path>/native/windows -jar dist\pong.jar

How to execute project with JOGL library?

I'm developing Java project with JOGL, but when I'm trying to execute my project I'll got the following message:
Catched FileNotFoundException: E:\Eclipse\Projects\FuzzyProject\lib\jogl2-rc10\gluegen-natives-windows-i586.jar (Can't find file), while TempJarCache.bootstrapNativeLib() of jar:file:/E:/Eclipse/Projects/FuzzyProject/lib/jogl2-rc10/gluegen-natives-windows-i586.jar!/ (file:/E:/Eclipse/Projects/FuzzyProject/lib/jogl2-rc10/ + gluegen-natives-windows-i586.jar)
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
How can I fix this problem?
From console java -Djava.library.path=<path to native library> -jar (if jar) <name of jar or class>
From code just System.loadLibrary(<path to native library>)
From Eclipse: Run Configuration -> Arguments -> VM Argiments->-Djava.library.path=<path to native library>
I assume you're running this from eclipse and on a windows machine, so have a look here: I installed JOGL but why wont Eclipse recognize my hello world program?
For gluegen, have a look here: java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path RCP Application

Categories

Resources