Programmatically load native library


I need to programmatically load a native library (ntlmauth.dll) from my plugin code, because it depends on the agent bitness (x86 or x64) I can't just use the java.library.path to do so. I tried:

String pluginDir = configuration.getAgentPluginsDirectory().getAbsolutePath();
String arch = configuration.getSystemInfo().bitness() == Bitness.BIT32 ? "x86" : "x64";

Inside my plugin the lib structure is:

- lib
  - native
      - x86
         - ntlmauth.dll
      - x64
         - ntlmauth.dll

It looks like the native library is load as expected, but later when trying to use it I get the following error:

I/O Error: SSO failed: Native SSPI library not loaded. Check the java.library.path system property.

Any idea what's happening and how to solve it?

Thanks a lot!

PD: What's the procedure to include JNI libraries in agent plugins?

Comment actions Permalink


After rethinking and checking a lot of things it looks like the problem is that the library itself look in the java.library.path, but of course I can't deploy my dll into the bin path of the agent.

I don't want to tell to the user to manually deploy the dll into the agent's jre folder so is there any way to solve this issue? or well, what's the advice about deploying native jni components to an agent?

Comment actions Permalink

There is a hacky way to change java.library.path system property. Unfortunately it is not enough to set it to new value, some reflection is also needed. Take a look at code in jetbrains.buildServer.NativeLibraryPathHacker. This class determines path to it's own jar file and adds directory where this jar is located to library path. After that dll files placed under WEB-INF/lib can be loaded by Java. As I said it's a hacky way, but sometimes you don't have other workarounds :)


Please sign in to leave a comment.