I'm trying to print the JNA version being used to my logs, at runtime.
How do I get the version of JNA through code at runtime?
The current JNA version is written at build time to a constant VERSION
in the appropriately-named Version
interface. That interface is package private, but is implemented by the Native
class, making the constant publicly available from Native
. (Linters may complain.) So you can simply do:
import com.sun.jna.Native;
public class Test {
public static void main(String[] args) {
System.out.println("JNA Version: " + Native.VERSION);
}
}
Output:
JNA Version: 5.6.0
You can also get the version of the native bits, which follow a different numbering scheme than the overall project version (which is incremented with new mappings that don't change the compiled native portions), but may be relevant in some contexts:
System.out.println("JNA Native Version: " + Native.VERSION_NATIVE);
The Native
class also exposes a boolean
isCompatibleVersion()
method which you can use to check whether JNA is at least the specified version or higher.