jna
Java Native Access
A Java library that lets you call functions from native operating system libraries written in C without writing any C code yourself. Just write a Java interface describing the functions you need and JNA handles the translation at runtime, replacing the old JNI approach.
Java Native Access, known as JNA, is a library that lets Java programs call functions from native operating system libraries (written in C or similar languages) without requiring developers to write any low-level glue code. Normally, doing this in Java requires a layer called JNI (Java Native Interface), which involves writing C code, compiling it for each platform, and managing a lot of configuration. JNA skips all of that: you write a Java interface describing the native functions you want to call, and JNA handles the translation at runtime.
The practical benefit is that Java applications can access platform-specific features, such as Windows system calls, macOS frameworks, or Linux kernel interfaces, without the usual setup burden. The library uses a small native stub internally to make the translation work, but developers do not need to touch or compile that stub themselves. From the developer's perspective, calling a native function through JNA looks almost identical to calling any regular Java method.
JNA ships in two parts. The core library handles the low-level binding mechanics. A second artifact called JNA Platform contains pre-written mappings for commonly used system functions across Windows, macOS, and Linux, so developers working with standard operating system APIs do not have to define those mappings from scratch.
The library has a long track record and is used by well-known projects including IntelliJ IDEA, Apache NetBeans, Elasticsearch, Apache Cassandra, and VLCJ (a Java wrapper for the VLC media player). It supports most platforms where Java runs, and because it relies on a standard tool called libffi under the hood, it can generally be compiled for any platform that supports that tool.
JNA is available through Maven Central, the standard repository for Java libraries, making it straightforward to add as a dependency. Full API documentation is published online. The project encourages questions and discussion through a mailing list and Stack Overflow.
Where it fits
- Call Windows API functions from a Java application without writing any C or JNI code.
- Access macOS or Linux system calls from Java using JNA Platform's pre-built mappings.
- Build a Java wrapper around a custom C library for use in a cross-platform desktop application.
- Integrate a native media library into a Java app without compiling platform-specific native stubs.