Adding .dll to java build path - java

I'm using a .jar library that needs additional .dll or .so to function.
I copied them in a folder in my eclipse project and then added that folder to the native library location in Properties -> Java Build Path -> Libraries. When I start my application in eclipse, it works well but when I export it as a runnable jar and then execute it, it doesnt work anymore and gives me a java.lang.UnsatisfiedLinkError error.
Is there a possibility to add these additional files inside the .jar and also add them to the java.library.path variable when running the application?
Regards

I would suggest creating new resources folder in Eclipse (if you are using it, since that folder will be on classpath), or just add it manually to classpath.

Related

Google Or-Tools : UnsatisfiedLinkError

I have created a spring application which uses google or-tools. For that, I am importing jniortools using System.loadLibrary("jniortools"). when I provide the .dll file and run the war file it runs perfectly. But when I provide the .so file path in lib, I get the unsatisfiedlinkerror.
Taken from here, a solution for using or-tools over Intellij:
To make it work using Intellij (over a windows machine) you need to:
Install Microsoft Visual C++ Redistributable for Visual Studio
Download and extract the OR-Tools library for Java
In intellij, add jar dependency to the 2 jars under the lib folder of the extracted files (each of the 2 jars separately, do not add to lib folder itself. This is why).
Add the lib library path to VM options. In Intellij edit your run-configuration and add to vm options: -Djava.library.path=<path to the lib folder that hold the jars>
Load the jni library statically by adding the below code to your class (as mentioned here.)
static {
System.loadLibrary("jniortools");
}

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

Exporting to Runnable jar with extra native code libraries in eclipse

I am having trouble exporting my java project from eclipse as a jar executable file. My java project uses an external library (its called jri). I have exported the jri.jar file and set the library path for its native library in eclipse, and it works great in development in eclipse. However, when I export it as an executable jar file I get the following error:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
I have placed a folder called lib in the same directory as my project's jar; this lib folder contains jri's native library. jri's native library is not in one file but in a folder. This is the same setup I have in eclipse.
The way I am exporting my project in eclipse is
Export...
Java > Runnable JAR file
Copy required libraries into a sub folder next to the generated Jar
Finish
And my folder is organized like this
folder project
project.jar
project_lib
jri.jar
jri native library folder
The MANIFEST.MF of my project.jar is:
Manifest-Version: 1.0
Class-Path: . project_lib/jri.jar
Main-Class: index
What I want to achieve is to give another person a folder including project.jar and anything else needed so she/he can run it without needing to install anything else.
Thanks so much
Add a script containing something like that:
#!/bin/bash
java -Djava.library.path=project_lib/native/ -jar project_lib/jri.jar
I export some java projects that way.
This is relatively hard to implement. The solutions I have seen involve extracting the native libraries in the JAR to an OS temp directory and then loading it. I would go for an integrated solution for that. One Jar and Java Class Loader support it, and on the second page you will find links to similar tools.
You can put the libraries inside your jar:
Export...
Java > Runnable JAR file
Package required libraries into generated Jar
Finish
I always export this way.
I don't know if it will work in your case, but worth a try.
Edit:
See these links:
Instalation, setup and setting environment properly
What to do when getting Cannot find JRI native library!
My guess is that this have something to do with LD_LIBRARY_PATH not correctly been set. Or the file wich it is searching for isn't in the path listed.
You know I had the similar problems
Could not extract native JNI library.
all above proposes can't help me. I couldn't stop and start gradle deamon by using follow command:
gradle --stop
I saw that gradle deamon still not stopped in my processes. That's why I kill it in my process and all will be fine :)

Project Root in Java Including .dll

Hey I'm running Eclipse and I'm making a project that uses JMyron and apparently I need to copy a .dll to the root of my project... what is that and how do I do it in Eclipse (I'm a noob).
Note... I also have to add a .jar to my classpath

Create java application jar file in eclipse

I have created a java application in eclipse, wich needs comm.jar and jexcel.jar and .property files so i have added to libray. I want to make a jar file out of my java appliction, including the external jar files added to the appliction.
How can I do it? To run serialport programs I have copied win32.dll into java_home/bin and comm.jar into java_home/jre/lib and javax.comm.properties into java_home/jre/lib, but when delivering the product it should run only by needing the jre.
How can I solve this? Please help me.
Thanks in advance,
suma
Although your question is not totally clear I suggest using the Fat Jar Plugin should allow you to achieve what you want.
You can use File > Export > Executable Jar which includes all libraries. There is also a checkbox to generate an ant build file as well as the jar in order to customize it further (I for instance make all the paths relative and remove the main-class flag).
You have two "path" issues. The Java Classpath and the path from which dlls are loaded.
If you were using a Java EE app server or OSGi then controlling these paths is addressed by the respective runtimes. Both Java EE and OSGi are likely to be overkill for small projects.
In which case you are delivering:
Your application JAR
The dependent jars
The DLLs
I suggest that on installing your app you place these artefacts into a suitable directory structure, for example .../myapp/lib for the jars and .../myapp/bin for the dlls. Don't copy them into the infrastructure directories, for example the JRE lib and bin, or into Windows32 - that just leads to version nightmares and mysteries when someone installs a new jre.
Having got that structure, how to control the paths? For the classpath, look at the Manifest.mf file. tutorial
For the DLL path, I know of no good alternative to setting OS level environment variables ** before ** launching the JVM. Hence you need a little batch/shell script to launch your app, setting the PATH appropriately.
You can also check maven.
You can right click on the project and say "Export". Now select "Java" in tree of choices. Under that select "Jar File". It'll guide you through the process and will allow you to export you project as a jar file.
Hope thats what you are looking for.
The recently released Eclipse 3.5 has a Export as runnable Jar which allows to put all dependent jars in a subfolder to the jar file, and get the Manifest right.
It is an adaption of the FatJar plugin. Works nicely!

Categories