native-utils | simple library class which helps with loading dynamic JNI | Wrapper library
kandi X-RAY | native-utils Summary
kandi X-RAY | native-utils Summary
A simple library class which helps with loading dynamic libraries stored in the JAR archive. These libraries usualy contain implementation of some methods in native code (using JNI - Java Native Interface).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Loads a library from the JAR archive
- Create a temporary directory
- Checks if is posix compliant
native-utils Key Features
native-utils Examples and Code Snippets
Community Discussions
Trending Discussions on native-utils
QUESTION
I am trying to develop a plugin for Fiji/ImageJ that relies on a native library (JNI).
The JNI library itself depends on libtiff
and fftw
. On OSX and Linux, I use the class NativeUtils and everything works fine.
On windows, I included binary versions of libtiff
and fftw
in the CMake
package and managed to link the JNI library against those (either statically of dynamically). However, the resulting JNI module does not include libtiff
or fftw
and I obtain an error when I try to load the JNI library with NativeUtils.loadLibraryFromJar
. This is also the case when I include the dependent .dll
in the .jar
since they are not extracted by NativeUtils
.
Here are the relevant lines in CMakeLists.txt
:
ANSWER
Answered 2020-Feb-20 at 21:10You can't load library from inside JAR without extracting it in a first place.
Take a look here at full sample where native code is embedded inside JAR and extracted when needed.
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031
Update
Well, in that case, when you need to pack more libs and you want to properly resolve locations, you need to play with runtime env a little bit.
Take a look here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo035
QUESTION
I develop an app in java that loads a C++ shared library using JNA. The detailed procedure is the following.
- Find library in the jar
- use
System.load( C_LIBRARY_PATH )
with the result of step 1 - Load library using JNA tools:
Wrapper INSTANCE = Native.loadLibrary( C_LIBRARY_PATH, Wrapper.class );
This procedure is used to create a wrapper of the c++ library and hence produces a java library that is used for other projects. Point 1 and 2 are inspired by the work of adamheinrich. The existence of the file is checked before calling the load
function.
When using the java wrapper in a project I randomly have an error like below. Could you guide me in debugging and try to control this random failure?
...ANSWER
Answered 2018-Jun-28 at 12:51I was accidentally loading twice the same library in multiple java classes. More precisely, the call Wrapper INSTANCE = Native.loadLibrary( C_LIBRARY_PATH, Wrapper.class );
was done in a nested interface that I replicated in all the different objects that were using the same c++ library. This, as reminded by @cubrr, is done statically at instantiation of the first object. Hence the library was loaded multiple times. Below a speudo-code illustrating my mistake.
QUESTION
I use JNA to load a c++ library (.so) in a java project. I package my library inside the jar, and load it from the jar when instantiating the java class that uses it. I do all this like so:
- mvn install compiles the c++ code and packages the outcome dynamic library inside the jar.
I call in a static context when instantiating the LibraryWrapperClass the following
...
ANSWER
Answered 2018-Mar-21 at 14:25How could I debug?
1. with strace
strace will give you what files Tomcat is trying to open : strace -f -e trace=file -o log.txt bin/startup.sh
After this, look for packageName in log.txt, or other files not found with :
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install native-utils
You can use native-utils like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the native-utils component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page