https://github.com/sshtools/nih
Native Integration Helpers
https://github.com/sshtools/nih
Last synced: 12 months ago
JSON representation
Native Integration Helpers
- Host: GitHub
- URL: https://github.com/sshtools/nih
- Owner: sshtools
- License: apache-2.0
- Created: 2025-01-04T19:25:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-22T10:17:46.000Z (about 1 year ago)
- Last Synced: 2025-05-22T10:46:05.864Z (about 1 year ago)
- Language: Java
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nih

[](https://maven-badges.herokuapp.com/maven-central/com.sshtools/nih)
[](https://coveralls.io/github/sshtools/nih)
[](https://javadoc.io/doc/com.sshtools/nih)

NIH (or **Native Integration Helper**), is a tiny library for Java 22 and above that helps with loading native libraries. Based on code from JNA, it deals with bundling platform specific libraries along with your application jars, and overcoming some problems with locating such libraries when using the new FFMAPI available in modern Java.
## Configuring your project
The library is available in Maven Central, so configure your project according to the
build system you use. For example, for Maven itself :-
```xml
com.sshtools
nih
0.9.0
```
### Snapshots
*Development builds may be available in the snapshots repository*
```xml
oss-snapshots
https://oss.sonatype.org/content/repositories/snapshots
true
false
..
com.sshtools
nih
0.9.1-SNAPSHOT
```
## How To Use With OS Supplied Libraries
Simply use `Native.load()` methods instead of FFMAPIs default methods to obtain a `SymbolLookup`. This deals with several platform specific problems that as of writing, the base Java tools do not deal with (Linux library paths with symbolic links, and Mac OS frameworks do not seem to be handled well).
For example, `Native.load("c", Arena.ofAuto());` will locate that standard C library.
## How To Use With Bundled Libraries
First, include compiled shared libraries as a Java resource (e.g. `src/main/resources`) in the sub-path `META-INF/shared-libraries//`.
Then to load the library in Java and obtain a `SymbolLookup`, use `Native.load()` methods.
For example, say you are working on 64-bit Linux and had a native shared library compiled from `tray.c`. Your native `Makefile` produces a `libtray.so`.
You would place `libtray.so` into `src/main/resource/META-INF/shared-libraries/linux/x86-64`, and then use `Native.load("tray", Arena.ofAuto())` to obtain the library handle.
If you then want to add Windows support, you would then place your `tray.dll` into `src/main/resource/META-INF/shared-libraries/windows/x86-64`.
## Origin
The 2 classes in this library originated from JNA, but were adapted to be useful with Java's own FFMAPI. This code, and our minor additions to it are licensed under LGPL 2.1 or later and Apache License 2.0. (starting with JNA version 4.0.0).