UnsatisfiedLinkError Java with Rxtx library - java

I am trying to communicate to Arduino with Java, so I'm using the rxtx library. I've downloaded the library and placed the respective files in my java project's folder. I put the rxtxxjar in a lib folder in the java project's folder, and I left the serial.jnlib straight into the java project's folder. I've taken the SerialTest code off of the arduino website, and I've tried to run it but I keep getting the UnsatisfiedLinkError. I've researched this question, and I've seen people saying basically the following in different ways:
Go to Project -> properties -> Java build path ->Find your .jar. Click
on + to open the JAR's properties. Select Native library location and
edit it to point to RXTX's shared library (.DLL, .so, .dylib).
However, I have no idea how to do the pointing to the shared library, especially since I don't see any .dll, .so, or .dylib file, and I cannot use the .jnlib because it is greyed out. Also on a smaller note, by my .jar is that just the project? I work in Eclipse Java EE.

You can use
System.load("Absolute path to your jni library");
This works fine on my project.

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");
}

Runinng jar application error [duplicate]

I have made a Java game using LWJGL, which requires some native files. It all works fine in Eclipse. I want to include the .dll files inside a JAR file, but everytime I try, LWJGL can't find the natives. I have already tried using jarsplice or fatjar, but to no avail. I know minecraft is also programmed using LWJGL, and it somehow manages to load the natives from another folder.
Is there a way to package native files into a JAR file and let a 3rd party library, like LWJGL access them? If not, how would I approach loading them from an external folder?
EDIT: Somehow it worked with the natives in the same directory as the JAR file. I would still like some explanation and perhaps some other methods, though.
I just ran into this a few weeks ago. Alas, I do not have links, but I found that you cannot reference native files stored inside of a jar file. You have to either programatically extract them before you reference them, or you have to install them alongside your jar file.
I went with the second option and just have Eclipse pack the whole collection into a zip file for distribution.
For the first option, one place to look would be the source code for JNA. They ship dll's/binaries inside their jar file and extract then on demand.

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.

Integration of Java and Python Code in One Eclipse Project

I am writing a compiler in Python using Eclipse with PyDev. I've come to a stage where I needed to write some code in Java. I'm wandering if there is a way of combining these into a single project, because at the moment I have two separate projects, and whenever I need to change the Java code, I have to manually copy the .class file into the Python project.
If this is not possible, what would you suggest is the most elegant way of structuring the files of these projects, and how should I set up my build process?
Thanks.
You can keep things in separate projects without having to copy the .class files to the Python project provided that you make that project a PyDev project and add the place that contains the .class files (i.e.: bin folder) as a source folder in the PyDev configuration (and reference that project from your Python project).
Take a look at "Project reference for Jython users" (in the end of http://pydev.org/manual_101_project_conf2.html).
I think you could also do what you asked in your question: create a java project, set it as a PyDev project too (right click that project > pydev > set as pydev project) and configure the PyDev project properties setting the PYTHONPATH to the place where you have your Python files and add another entry to the bin folder (i.e.: where the .class files exist). Not sure if it'd be better to keep those as 2 separated projects though.
I think Jython would be ideal here, as the Python code essentially gets translated to Java bytecode and run on the Java virtual machine, making it easy to communicate between the two. Also, pydev itself integrates well with Jython.

Using JNI libraries in an Eclipse Java project

I have inherited a jar file with two JNI class files and related libraries (.so files). I am not familiar with c++ or JNI. How do I reference these in my Java project in Eclipse?
So far, I have created a Java project, added the jar file as an external jar to the buildpath and then have attached the folder containing the jni libraries using Properties -> Java Build Path -> Libraries tab, expand the jar file (containing the class files) and edit "Native library location".
I have a driver program in Java with a main method which makes the jni object. Eclipse says "ObjectName cannot be resolved to a type".
Why would this happen even though the class files are in the build path?
I have just put all the libraries under /src/main/resources.
Right click on the project and go to Properties>JavaBuildPath. In the Libraries section expand the jar you need the libraries for and click on "Native library location", then press "Edit..".
You just need to give the /src/main/resources path as location.
Then in the "Order and Export" section of the Properties>JavaBuildPath you need to make sure that /src/main/java is above /src/main/resources.
In the Java file, where you instanciate your JNI defined object, make sure you have imported the class files:
import your.jni.classes;
I suggest you have a look here, at the video:
http://mmbtools.crc.ca/content/view/53/78/
(look at this video on Youtube and set the resolution to 720px to see clearly)
It is a good step-by-step example of how to integrate JNI classes in a Java application, in Eclipse. It is pretty much what you're trying to do.
Hope it helps,

Categories