UnsatisifedLinkedError : Could not locate stub library in jar file - java

I am trying to use this jnr-jffi library. It appears to have a dependency on jffi so I have also built that and included in my libs folder.
My code to load the native code is as follows:
MATH_LIB = LibraryLoader.create(MathLib.class).load("math");
MATH_LIB.Multiply(1, 2);
And I get the following error:
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: could not locate stub library in jar file. Tried [jni/Darwin/libjffi-1.2.dylib, /jni/Darwin/libjffi-1.2.dylib]
For what it's worth, I did include a folder jni that appears to contain a bunch of native libraries for various platforms.
How I can proceed to load my native code using this library.
Please note that I have tried adding various paths when launching my project and also adding the libraries to various locations on my machine, with no success.
That would mean I need to figure out how to debug further into this? Any advice is welcome.

It would be easiest to use maven when using JNR. Maven will automatically resolve all the needed dependencies.
You can just add this to your pom.xml:
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-ffi</artifactId>
<version>2.0.9</version>
</dependency>
Or find a more up-to-date version here.

You need the platform specific version of the file: libjffi-1.2.dylib
Refer to this issue & try to find a relevant jar for your platform version which would contain the above library file.

Related

Java, Maven: Need help embedding j2mod library into a java plugin

I need some help using j2mod, a java library for Modbus TCP/RTU into a plugin for Universal Robots.
Using the maven-bungle-plugin
What I have tried:
Including dependencies one by one (never ending dependency tree)
Using the tag to include the j2mod package in jar (program starts with a requires 'jSerialComm' error)
Using tag to include all dependencies of scope compile and runtime (program starts with a requires 'org.slf4.impl' error and I cant seem to figure out a way to adapt slf4j to log4j.)
I know from snooping around the polyscope simulator program's files. The simulator seems to use log4j-api-2.3.jar and a modified-log4j-core-1.11.6.jar.
Any insights on using j2mod or a similar java Modbus TCP/RTU library in an embedded system environment will me helpful.
Thank you

How to include JAXB functions in AnyLogic 8.4.0?

I have an AnyLogic model that uses JAXB functions for parsing an XML file. The model used to work earlier but it doesn't now since apparently the newer versions of Java don't include JAXB. The online examples of how to do this in Java programs doesn't fit AnyLogic environment.
Based on online searches, I have downloaded and included the jaxb-api-2.4.0-b180830.0359.jar file in AnyLogic model. That by itself doesn't work and leads to the following error:
SEVERE: null
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
I then added the following in the import section:
import java.xml.bind;
import com.sun.xml.bind;
Also tried:
import java.xml.bind.*;
import com.sun.xml.bind.*;
Both resulted in the same error:
The import com.sun.xml.bind cannot be resolved.
The import java.xml cannot be resolved.
On line guidance from for example https://www.dariawan.com/tutorials/java/using-jaxb-java-11/ recommend adding the dependencies using below code to Java programs:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.api.version}</version>
</dependency>
How do we specify such dependencies via AnyLogic interface?
Once JAXB functions work, they should lead to parsing the data in XML file and creating and populating corresponding objects in AnyLogic as was the case before.
Sounds like you didn't add the .jar file properly in AnyLogic...
Click on your model in the projects view (the top-most entry above all agents and Main):
In the properties, you can add your .jar file under the "Dependencies" tab:
Do follow the advise to "keep a copy in your model folder" so it doesn't get lost.
Now you can import what you need and it will work (unless the .jar file is broken itself).
PS: Might be better to rephrase your question to "How to load an external jar file to my model dependencies"
The problem
As already stated in the question, the problem is this:
JAXB as a Java tool for XML treatment has been removed from the Java standard library beginnig with Java 9. The reason for this decision was to make the standard Java library more lightweight.
Dependencies in Java
This can be solved by including the removed package(s) manually into your project. As a lot of people already had this problem, quite an amount of SO questions for this exist, like this and this.
In these answers it is suggested to 'load dependecies', eg like this:
<!-- https://mvnrepository.com/artifact/pacakgename -->
<dependency>
<groupId>packagename</groupId>
<artifactId>modulename</artifactId>
<version>1.0.0</version>
</dependency>
These dependency statements are interpreted by the Java IDE such as Eclipse (with a package manager such as Maven), and the stated packages then get automatically loaded from an online package repository and included in the project.
In AnyLogic, the procedure is slightly different!
Dependencies in AnyLogic
In AnyLogic the exact same thing is happening when you click on your project in the AnyLogic editor, and add a JAR file under the Dependencies tab, see Benjamin's answer for this. In order to do that you will manually have to find the JAR file in a package repository and download it first.
Needed Pacakges
This is where I am not completely sure. I'll got an example to run when I included the following packages, but probably there is redundancy, so you might want to try around with variations of them:
javax.xml.bind / jaxb-api / 2.3.0-b170201.1204
javax.activation / activation / 1.1
org.glassfish.jaxb / jaxb-runtime / 2.3.0-b170127.1453
com.sun.xml.bind / jaxb-impl / 2.2.11
com.sun.xml.bind / jaxb-core / 2.2.11
Example
I created a simple example model in AnyLogic, that is based on this blog post. You can run and download it (including the dependeny Java packages) here.

How to generate protobuf 3.0 jar java?

I am quiet familiar with protobuf 2.5. I was trying to use protobuf3.0. It seems that the jar is to be generated form the source code available online. But when i import the source code into eclipse and try to create a jar, i can see many errors in the following files
/protobuf3/src/com/google/protobuf/Descriptors.java,
/protobuf3/src/com/google/protobuf/DynamicMessage.java
/protobuf3/src/com/google/protobuf/ExtensionRegistry.java
/protobuf3/src/com/google/protobuf/MessageReflection.java
/protobuf3/src/com/google/protobuf/TextFormat.java
/protobuf3/src/com/google/protobuf/UnsafeUtil.java
This is one of the errors "the import com.google.protobuf.DescriptorProtos cannot be resolved".
Is this the right way to generate the jar (or) is it available anywhere (or) is the full source code available anywhere.
Any help would be appreciated.
Thanks.
This is where i downloaded the source code protobuf3.0-source code
You can find a compiled (JAR) version of Protobuf to download here:
http://search.maven.org/remotecontent?filepath=com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar
I recommend you look at a build manager such as https://maven.apache.org/ to automatically handle fetching dependencies (libraries) for you.

java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setSaveAggressiveNamespaces()Lorg/apache/xmlbeans/XmlOptions;

I am trying to write a program which write the data in Excel. But i keep getting an error which is shown below:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setSaveAggressiveNamespaces()Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:56)
at wriExcel.main(wriExcel.java:19)
On finding the solutions, I could only find that I should use XMLBeans 2.0 or higher.
But, I am using xmlbeans 2.3.0.
Is there any other reason for this error.
Use xmlbeans-2.6.0.jar which resolves my problem...!
This error might be because required needed for the project is not there so you have to download jar and then add that jar to your classpath
here is the link
find out which jar you need
Use the xmlbeans jar file shipped with PIO libraries, and avoid to download from any other source as there will be jar file conflicts.
You can find the xmlbeans under "ooxml-lib" shipped with PIO.

Indirectly referenced from required .class file

I'm getting an error message when I try to build my project in eclipse:
The type weblogic.utils.expressions.ExpressionMap cannot be resolved. It is indirectly referenced
from required .class files
I've looked online for a solution and cannot find one (except for those sites that make you pay for help). Anyone have any idea of a way to find out how to go about solving this problem? Any help is appreciated, thanks!
How are you adding your Weblogic classes to the classpath in Eclipse? Are you using WTP, and a server runtime? If so, is your server runtime associated with your project?
If you right click on your project and choose build path->configure build path and then choose the libraries tab. You should see the weblogic libraries associated here. If you do not you can click Add Library->Server Runtime. If the library is not there, then you first need to configure it. Windows->Preferences->Server->Installed runtimes
Add spring-tx jar file and it should settle it.
Have you Googled for "weblogic ExpressionMap"? Do you know what it is and what it does?
Looks like you definitely need to be compiling alongside Weblogic and with Weblogic's jars included in your Eclipse classpath, if you're not already.
If you're not already working with Weblogic, then you need to find out what in the world is referencing it. You might need to do some heavy-duty grepping on your jars, classfiles, and/or source files looking for which ones include the string "weblogic".
If I had to include something that was relying on this Weblogic class, but couldn't use Weblogic, I'd be tempted to try to reverse-engineer a compatible class. Create your own weblogic.utils.expressions.ExpressionMap class; see if everything compiles; use any resultant errors or warnings at compile-time or runtime to give you clues as to what methods and other members need to be in this class. Make stub methods that do nothing or return null if possible.
This issue happen because of few jars are getting references from other jar and reference jar is missing .
Example : Spring framework
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.factory.annotation.Autowire. Fix the build path then try building this project SpringBatch Unknown Java Problem
In this case "org.springframework.beans.factory.annotation.Autowire" is missing.
Spring-bean.jar is missing
Once you add dependency in your class path issue will resolve.
I was getting this error:
The type com.ibm.portal.state.exceptions.StateException cannot be resolved. It is indirectly referenced from required .class files
Doing the following fixed it for me:
Properties -> Java build path -> Libraries -> Server Library[wps.base.v61]unbound -> Websphere Portal v6.1 on WAS 7 -> Finish -> OK

Categories