load java native file lib - java

I would like to use some native files and use some files out of an android project. I need this files for my own java project and need to import the lib.
I am trying to load the lib with:
static
{
System.loadLibrary("mrclient_java");
}
The lib file "libmrclient_java.so" is in this folder: "/libs/armeabi/".
When I run the project following error appears:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mrclient_java 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 dont know how to configure the CLASSPATH or whatever to solve this problem.
I am not using android for this project. The android project itself runs perfectly.
EDIT:
I found this Question: How to set the java.library.path from Eclipse, but the same error still appear.

You have to add java.library.path to your command line that runs java. Something like the following:
java -cp YOURCLASSPATH -Djava.library.path=/libs/armeabi/ com.compnay.Main
Classpath is for loading java classes only. Library path is for loading native libraries.

Related

Issues with creating a JAR file with Eclipse

I have to extract a runnable jar file from an Eclipse project. I know that choosing Package required libraries into generated JAR makes the jar file slower than choosing Extract required libraries into generated JAR, but the problem is that if I extract the libraries, rather than package them, the application doesn't start because of the following error:
Catched FileNotFoundException: C:\Users\rober\Desktop\palbo-natives-windows-amd64.jar (The system cannot find the file specified), while TempJarCache.bootstrapNativeLib() of jar:file:/C:/Users/rober/Desktop/palbo-natives-windows-amd64.jar!/ (file:/C:/Users/rober/Desktop/ + palbo-natives-windows-amd64.jar)
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.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at org.jzy3d.global.Settings.<init>(Settings.java:12)
at org.jzy3d.global.Settings.getInstance(Settings.java:21)
at org.jzy3d.chart.Chart.<init>(Chart.java:59)
Of course, all the required libraries have been added to the Eclipse project and thus the application perfectly works if launched in Eclipse.
Is there a way to avoid this issue? In other words, is there a way to make my jar finding all the required libraries even if I choose the option Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR?
Additional info:
even if I choose the option Package required libraries into generated JAR, I need to have some .dll files (e.g. gluegen-rt.dll, jogl.dll, jogl_awt.dll, jogl_cg.dll) in the same folder of the runnable jar files in order to make it opens correctly. Moreover, the application takes forever to be initialized.
Summary:
Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR: the application cannot be opened because of the above posted Exception.
Package required libraries into generated JAR: noteworthy performance issue.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook while running jar file

I have written a java program to convert input xml file into some other xml file. While doing this I am using excel file and for accessing xml file I used apache-poi libraries.
When I run my program in eclipse it works fine and gives required results. Now I export the project in jar file and I selected my main class while exporting into jar. But when I run the jar file, I am getting following exception:
D:\>java -jar EDR_to_DER_with_excel.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
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)
Could not find the main class: com.unisys.xml.TestExcel. Program will exit.
The error is related to libraries that I am using. But I don't know why it's coming, because I am able to run the program in eclipse. Is the library class available in jar file> If not how can I give it to the jar while exporting?
It appears that the Apache POI Libraries are not in the classpath
Add the location of the libraries to PATH variable of your system (Assuming windows based on D:\ drive in question).
Export project do not included the external jars by default.
You have to add the third party lib to the classpath:
java -cp <lips> -jar EDR_to_DER_with_excel.jar
I got the solution. I followed simple approach.
-> Right click on project
-> Export
-> as Runnable jar
-> select radio button "Package required libraries into generated jar"
-> finish
This approach worked for me :)
I got the answer of the query in this case the jar files are missing in the program .Please check there are added from proper path.
This worked for me

Trying to use RXTXcomm.jar with a executable I made

I wrote a program to communicate with an arduino using the RXTXcomm.jar. It works in eclipse because I "Added External Jars" in the edit class path option.
I got the tutorial off this website: http://www.drdobbs.com/jvm/control-an-arduino-from-java/240163864. I originally tried running the command on that website to get the RXTXcomm.jar to work without having to use the eclipse work around but I couldnt get it to work (after much time and research). However, now I want to make an .exe out of my program. I used Launch4J to make an .exe and it works but, like before the eclipse work around, the serial communication aspect doesn't work.
I have thought of two fixes, I do not know the plausibility of either however:
1) Some how export my java gui to a jar file that contains the RXTXcomm.jar that was added when using eclipse work around
2) Write a script that I run once to set the computer up that will allow me to use the RXTXcomm.jar
The main goal is to create this .exe and put all the supporting files in a folder with it, with maybe a setup/readme file to get it working on any PC.
Here is my stackup when I run just the [myprogram].jar file:
java.exe -jar [myprogram].jar
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while
loading gnu.io.RXTXCommDriver
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no rxtxSe
rial 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)
(AND MORE)
I have very little knowledge of what happens behind the scenes of java, I mostly understand the code only. I think that is why I am having trouble with this.
Thank you #hoijui,
I ended up just copying the rxtxSerial.dll to the same directory that the exe is run from and now it works. This directory also includes the RXTXcomm.jar as well. When making the exe in Launch4J I made a custom class path:
The "Main Class" I selected the jar I made from eclipse, then for the class path I added:
echo %CD%\RXTXcomm.jar
and
echo %CD%\rxtxSerial.dll.
I am not sure if this is needed to work but its there and it work so I am not messing with it.
Thanks for the help #hoijui

UnsatisfiedLinkError: no j3dcore-ogl in java.library.path

I have a project in eclipse, runs perfectly fine in the ide when I click run, but I need to export it into a runnable jar file which also works fine. But when I try to run it it throws an exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
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.<clinit>(VirtualUniverse.java:299)
at javax.media.j3d.GraphicsConfigTemplate3D.getBestConfiguration(GraphicsConfigTemplate3D.java:321)
at java.awt.GraphicsDevice.getBestConfiguration(GraphicsDevice.java:207)
at com.sun.j3d.exp.swing.JCanvas3D.<init>(JCanvas3D.java:228)
at com.sun.j3d.exp.swing.JCanvas3D.<init>(JCanvas3D.java:178)
at mainproject.MainPanel.<init>(MainPanel.java:72)
at mainproject.MainWindow.<init>(MainWindow.java:42)
at mainproject.MainWindow.main(MainWindow.java:23)
I have been googling it for 2 days now, tons of results, none helpful.
I export it by going to file->export->java->Runnable jar file->i bubble extract required libraries into generated jar, choose the correct configuration, save the file in a specified folder, then it saves just fine. Or at least so I think. The java.library.path goes to the jre lib folder, but when i run it in eclipse it goes to the .so for j3d, i tried changing it using System.setProperty but to no success. I have a feeling that is the problem, but when I tried to fix it nothing happened. I'm using the most up to date java3d library (1.5.2 I believe).
Any suggestions?
If I set
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jni
it works.

Eclipse java lwjgl no lwjgl in java.library.path

I installed and putted lwjgl library and natives to /lib folder. On eclipse Java build path setted library location and native library location. When i try to run it on eclipse, it works, but when i export it as a runnable jar, it doesn't run, and throws error:
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:132)
at Main.start(Main.java:9)
at Main.main(Main.java:31)
Tried to set run properties VM argument to -Djava.library.path="lib/" but it doesn't work too.
P.S. Tried to put the native .dll's to same folder as the jar is and it works, but I want to .dll's to be in other folder.
Thanks!
Found an answer. You can do it with custom .bat file and put there -Djava.library.path="lib/", but mine solution is to programmaticaly do that with next line:
System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/lib/");
Have you tried using JarSplice? It is a free Java .jar packaging program found here:
Ninja Cave - JarSplice
Follow the instructions. All the documentation is on this site. Just make sure that the JAR you use for your program is just an eclipse JAR file, not a runnable jar. When you start up JarSplice, add the appropriate Jars, Natives, define your main class, and simply create a runnable JAR. No need to set up VM configurations, and also you can export to Windows.exe, and MacOSX. If all goes well, you should have a double-clickable runnable jar. Hope this helps. It's how I've packaged LWJGL games in the past :)

Categories