Q:

LockDisplay: Unable to load X11 when using JNA to lock display

I am trying to lock the display (disallowing the user to use the keyboard and mouse) in Java, using X11 through JNA.
However, when I try running the application on Windows, I get this error:
java.lang.UnsatisfiedLinkError: Unable to load library 'X11': com.sun.jna.Native.open(Ljava/lang/String;)J
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:393)
    at com.sun.jna.Native.loadLibrary(Native.java:378)
    at com.sun.jna.platform.unix.X11.<clinit>(X11.java:347)
    at octostar.LinuxHelper.blockInput(LinuxHelper.java:77)
    at .... ....

My code is this (the input parameter is a boolean 'block'):
        boolean returnVal = true;
        X11.Display dpy = null;
        final X11 x11 = X11.INSTANCE;
        final Xss xss = Xss.INSTANCE;

        try {
            dpy = x11.XOpenDisplay(null);
            if (block)
                xss.XLockDisplay(dpy);
            else
                xss.XUnlockDisplay(dpy);

        } catch (Exception ex){
            returnVal = false;
        } finally {
            if (dpy != null)
                    x11.XCloseDisplay(dpy);
            dpy = null;
        }

        return returnVal;

The error occurs at X11.INSTANCE (which is the line octostar.LinuxHelper.blockInput(LinuxHelper.java:77) as in the error message above)
In another part of my code, I get this error:
java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.platform.unix.X11
    at octostar.LinuxHelper.getIdleTimeMillis(LinuxHelper.java:50)

I tried typing X11 in terminal, and they told me to do an installation, which I did after that, but every subsequent time I type X11 it says it's not installed. When I type the installation command though, I am told that I have the latest version already.
This is all very confusing to me. If anyone could help shed some light on this I would greatly appreciate it!

A:

JNA needs to be able to find libX11.so* when it looks up the functions you're calling.  On linux, you may need to set LD_LIBRARY_PATH to include the path to the X11 libraries.
(from the comments): LD_LIBRARY_PATH must be used in order to find dependent libraries, but setting the system property jna.library.path will allow you to indicate where explicitly loaded libraries may be found (i.e. those loaded with Native.loadLibrary()).

