https://github.com/stardust-enterprises/yanl
Yet Another Native Loader for the JVM.
https://github.com/stardust-enterprises/yanl
java jvm kotlin native
Last synced: 6 months ago
JSON representation
Yet Another Native Loader for the JVM.
- Host: GitHub
- URL: https://github.com/stardust-enterprises/yanl
- Owner: stardust-enterprises
- License: isc
- Archived: true
- Created: 2021-11-21T01:05:21.000Z (over 4 years ago)
- Default Branch: trunk
- Last Pushed: 2022-08-10T06:36:24.000Z (almost 4 years ago)
- Last Synced: 2024-04-22T11:19:07.579Z (about 2 years ago)
- Topics: java, jvm, kotlin, native
- Language: Kotlin
- Homepage: https://stardust-enterprises.github.io/yanl
- Size: 373 KB
- Stars: 6
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yanl - yet another native loader
[![Build][badge-github-ci]][yanl-gradle-ci] [![Maven Central][badge-mvnc]][yanl-mvnc]
yet another native library loader and extractor for the [JVM][jvm], written in [Kotlin][kotlin].
# why
other libraries simply do not fit my needs and/or are not as expandable/configurable as I would like.
# how use
you can import [yanl][yanl] from [maven central][mvnc] just by adding it to your dependencies:
## gradle
```kotlin
dependencies {
implementation("fr.stardustenterprises:yanl:{VERSION}")
}
```
## maven
```xml
fr.stardustenterprises
yanl
{VERSION}
```
# how work
this library can act as a replacement from your standard `System.loadLibrary`, with a bit more configuration setup.
consider the following example:
```java
package your.project;
public class Program {
public static void main(String[] args) {
// requires the native file to be in path
System.loadLibrary("coollib");
// do stuff...
}
}
```
this would require the library file to be somewhere on the `PATH` of the host machine.
one way of getting around this problem would be to extract the library from the jar archive to a known folder, then to
load it. this approach works but also requires extracting and loading the correct library for the correct processor
architecture (arch) and operating system (OS).
and this is where [yanl][yanl] performs: we take care of platform detection, library extraction and location with ease.
[//]: # (and even let you customize which version of the library you would
want to load based on processor flags)
taking back that previous example, let us see an extensive configuration:
```java
package your.project;
import fr.stardustenterprises.yanl.NativeLayout;
import fr.stardustenterprises.yanl.NativeLoader;
import fr.stardustenterprises.yanl.PlatformContext;
import fr.stardustenterprises.yanl.TempExtractor;
public class Program {
private static final NativeLoader nativeLoader =
new NativeLoader.Builder()
// this tells the loader to look for libraries
// in the /META-INF/natives directory
.root("/META-INF/natives")
// this sets where the loader is going
// to look for your libraries. you can
// check NativeLayout for default layouts
.layout(NativeLayout.HIERARCHICAL_LAYOUT)
// you can also only specify the layout's
// pattern, and it will automagically create
// it for you
//.layout("{os}/{arch}/{name}")
// set the extractor instance,
// see the Extractor interface
.extractor(new TempExtractor())
// set the context instance,
// see the Context interface
.context(new PlatformContext())
// create the loader
.build();
public static void main(String[] args) {
// replaces System.loadLibrary
nativeLoader.loadLibrary("coolLib");
// do cooler stuff...
}
}
```
***Note:** the above example is the **default** configuration for the [NativeLoader][blob-native-loader], so you could
replace the entire building process with the following:*
```java
package your.project;
import fr.stardustenterprises.yanl.NativeLoader;
public class Program {
private static final NativeLoader defaultLoader =
new NativeLoader.Builder().build();
}
```
# troubleshooting
if you ever encounter any problem **related to the library**, you can [open an issue][new-issue] describing what the
problem is. please, be as precise as you can, so that we can help you asap. we are most likely to close the issue if it
is not related to our work.
# contributing
you can contribute by [forking the repository][fork], making your changes and [creating a new pull request][new-pr]
describing what you changed, why and how.
# licensing
this project is under the [ISC license][blob-license].
[jvm]: https://adoptium.net "adoptium website"
[kotlin]: https://kotlinlang.org "kotlin website"
[yanl]: https://github.com/stardust-enterprises/yanl "yanl github repository"
[fork]: https://github.com/stardust-enterprises/yanl/fork "fork this repository"
[new-pr]: https://github.com/stardust-enterprises/yanl/pulls/new "create a new pull request"
[new-issue]: https://github.com/stardust-enterprises/yanl/issues/new "create a new issue"
[mvnc]: https://repo1.maven.org/maven2/ "maven central website"
[yanl-mvnc]: https://maven-badges.herokuapp.com/maven-central/fr.stardustenterprises/yanl "maven central repository"
[yanl-gradle-ci]: https://github.com/stardust-enterprises/yanl/actions/workflows/gradle-ci.yml "gradle ci workflow"
[blob-license]: https://github.com/stardust-enterprises/yanl/blob/trunk/LICENSE "LICENSE source file"
[blob-native-loader]: https://github.com/stardust-enterprises/yanl/blob/trunk/src/main/kotlin/fr/stardustenterprises/yanl/NativeLoader.kt "NativeLoader.kt source file"
[badge-mvnc]: https://maven-badges.herokuapp.com/maven-central/fr.stardustenterprises/yanl/badge.svg "maven central badge"
[badge-github-ci]: https://github.com/stardust-enterprises/yanl/actions/workflows/gradle-ci.yml/badge.svg?branch=trunk "github actions badge"