Class JLineNativeLoader

java.lang.Object
org.jline.nativ.JLineNativeLoader

public class JLineNativeLoader extends Object
Manages the loading of JLine's native libraries (*.dll, *.jnilib, *.so) according to the current operating system (Windows, Linux, macOS) and architecture.

This class handles the discovery, extraction, and loading of the appropriate native library for the current platform. The native libraries are essential for certain terminal operations that require direct system calls.

Usage

Call initialize() before using JLine features that require native support:
 JLineNativeLoader.initialize();
 

Library Loading Process

The loader attempts to find and load the native library in the following order:
  1. From the path specified by the library.jline.path system property
  2. From the JAR file's embedded native libraries
  3. From the Java library path (java.library.path)

Configuration Options

The following system properties can be used to configure the native library loading:
  • library.jline.path - Custom directory path where native libraries are located. The loader will check both [library.jline.path]/[os]/[arch] and [library.jline.path] directly.
  • library.jline.name - Custom name for the native library file. If not specified, the default name will be used (e.g., "jlinenative.dll" on Windows).
  • jline.tmpdir - Custom temporary directory for extracting native libraries. If not specified, java.io.tmpdir will be used.
  • java.library.path - Standard Java property for native library search paths, used as a last resort.

Platform Detection

The loader automatically detects the current operating system and architecture using OSInfo to determine which native library to load. Supported platforms include:
  • Operating Systems: Windows, macOS (Darwin), Linux, AIX
  • Architectures: x86, x86_64 (amd64), ARM (various versions), PowerPC, and others

Temporary Files

When loading from the JAR file, the native library is extracted to a temporary location. These temporary files:
  • Include version and UUID in the filename to avoid conflicts
  • Are automatically cleaned up on JVM exit
  • Old unused libraries from previous runs are cleaned up

Troubleshooting

If the library fails to load, an exception is thrown with details about:
  • The detected OS and architecture
  • All paths that were searched
  • The specific error that occurred

Java Module System (JPMS) Considerations

When using JLine with the Java Module System, you may need to add the --enable-native-access=ALL-UNNAMED JVM option to allow the native library loading.
See Also: