package org.ringojs.wrappers;

import org.ringojs.util.POSIXSupport;

/**
 * A wrapper class to allow retrieving jnr-posix support while protecting
 * the caller against NoClassDefFoundError if jnr-posix support is not installed.
 */
public class POSIX {

    public static Object getPOSIX() throws ClassNotFoundException {
        try {
            return POSIXSupport.getPOSIX();
        } catch (NoClassDefFoundError noclass) {
            throw new ClassNotFoundException(noclass.getMessage(), noclass);
        }
    }
}

package org.ringojs.wrappers;

import org.ringojs.util.POSIXSupport;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * A wrapper class to allow retrieving jnr-posix support while protecting
 * the caller against NoClassDefFoundError if jnr-posix support is not installed.
 */
public class POSIX {

    public static Object getPOSIX() throws ClassNotFoundException {
        return AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                try {
                    org.jruby.ext.posix.POSIX posix = POSIXSupport.getPOSIX();
                    // call some method to make sure native library gets loaded
                    posix.getuid();
                    return posix;
                } catch (NoClassDefFoundError noclass) {
                    throw new RuntimeException(noclass);
                }
            }
        });
    }
}

Make sure native POSIX library gets loaded in privileged action.