Java binds through JNA, so there is no JNI layer for you to compile and no per-platform native build in your own project — the SDK ships the native libraries and JNA loads the right one.
<dependency>
<groupId>com.keynub</groupId>
<artifactId>keynub-licdongle</artifactId>
<version>1.1.1</version>
</dependency>Code language: HTML, XML (xml)
Reading a license
try (LicenseDongleContext ctx = new LicenseDongleContext();
Dongle dongle = ctx.open()) { // first dongle found
dongle.verifyGenuine(); // throws unless genuine
try (Session session = dongle.openSession()) {
byte[] license = session.readRecord("license");
}
}Code language: Java (java)
Dongle implements AutoCloseable, so try-with-resources closes the device on every path out of the block.
Why Java needs the data-gating pattern badly
Java bytecode decompiles almost perfectly. A licence check written as if (licensed) is visible in any decompiler and removable with a bytecode editor in minutes, and obfuscators only raise the effort. This is not a Java weakness so much as a reason not to rely on a branch at all.
And the rule that matters in every language: do not branch on a boolean. Encrypt data your program genuinely needs with appEncrypt at build time and decrypt it through the dongle at run time, so removing the check leaves the program with nothing to compute rather than a working unlicensed copy.
Resources and error handling
The context, the dongle and the session all implement AutoCloseable, so try-with-resources closes them in the right order and a session cannot quietly outlive the device it came from. Failures arrive as an exception carrying the numeric status from the C ABI, with subclasses for the cases worth catching separately, so you are not comparing integers by hand.
The binding is a thin JNA wrapper: no protocol parsing and no cryptography in Java, all of that in the same native core every other binding uses. Java 17 or later, on Windows, Linux and macOS, with no driver to install.
Code
Runnable sample: java/VerifyAndRead.java. Binding source: bindings/java. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.
All supported languages · All industries · Buy a KeyNub · Ask us something