Using native lib with JNI in driver module

Hi,

I have few question:

it is possible to use a JNI dll native library in Ignition?

I have a jar file that need a JNI/dll to run.
That jar is a library of my ignition driver module.

How can i pack the JNI/dll in the module and use it in Ignition?

Thanks,
Stefano

It’s possible, but a little on the difficult side.

Have you used JNI before? Will you be the one making the call to System.load() or System.loadLibrary() or are you using a 3rd-party library/jar that does that on its own?

Hi Kevin,

yes, I used before, but not so much.

I’m using System.loadLibrary().

At the moment I found that solution:
a. in the driver I loaded the library: static {System.loadLibrary(“myLib”);}
b. then i copied the myLib.dll in the Ignition lib directory.

The solution works, but it’s not “elegant” :slight_smile:
Have you some suggestion or better solution?

May I ask you another thing not inherent native lib in this post? Or I have to open a new one?

Thanks,
Stefano

There isn’t exactly an elegant solution to this.

One solution is to do what you do; place the native library in Ignition’s lib folder (which gets added to java.library.path during startup via reflection voodoo) and then use System.loadLibrary().

The other more “portable” solution is to package the native library inside one of your jar files and during module startup copy the native library to a temporary directory and use System.load() on it.

I’m using loadLibrary as well and I get this:
com.inductiveautomation.ignition.common.modules.ModuleLoadException: Unable to load hook class “company.com.focas_ignition.GatewayHook” for module “company.com.focas-ignition”


Caused by: java.lang.UnsatisfiedLinkError: C:\Program Files\Inductive Automation\Ignition\lib\FwlibWrapper.dll: Can’t find dependent libraries
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(Unknown Source)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(Unknown Source)
at java.base/java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.base/java.lang.Runtime.loadLibrary0(Unknown Source)
at java.base/java.lang.System.loadLibrary(Unknown Source)
at company.com.focas_ignition.FocasWrapper.(FocasWrapper.java:12)
at company.com.focas_ignition.GatewayHook.(GatewayHook.java:29)

There is a few DLLs that FwlibWrapper.dll link to. I’ve tried putting them in C:\Program Files\Inductive Automation\Ignition\lib along with FwlibWrapper.dll. I realize this is probably a jetty issue with its class loader. I also tried adding the dependent DLLs in a library on the PATH.

What does ignition use for a JRE? does it use the JRE installed or does it use its own packaged JRE?

Ignition 8.x uses its own JRE. On the gateway you can find it in the lib/runtime folder.