/** Attempt to extract a native library from the current resource path, * using the current thread context class loader. * @param name Base name of native library to extract. May also be an * absolute resource path (i.e. starts with "/"), in which case the * no transformations of the library name are performed. If only the base * name is given, the resource path is attempted both with and without * {@link Platform#RESOURCE_PREFIX}, after mapping the library name via * {@link NativeLibrary#mapSharedLibraryName(String)}. * @return File indicating extracted resource on disk * @throws IOException if resource not found */ public static File extractFromResourcePath(String name) throws IOException { return extractFromResourcePath(name, null); }
try { String libName = "/com/sun/jna/" + Platform.RESOURCE_PREFIX + "/" + System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib"); File lib = extractFromResourcePath(libName, Native.class.getClassLoader()); if (lib == null) { if (lib == null) {
File embedded = Native.extractFromResourcePath(libraryName, (ClassLoader)options.get(Library.OPTION_CLASSLOADER)); try { handle = Native.open(embedded.getAbsolutePath(), openFlags);
/** Attempt to extract a native library from the current resource path, * using the current thread context class loader. * @param name Base name of native library to extract. May also be an * absolute resource path (i.e. starts with "/"), in which case the * no transformations of the library name are performed. If only the base * name is given, the resource path is attempted both with and without * {@link Platform#RESOURCE_PREFIX}, after mapping the library name via * {@link NativeLibrary#mapSharedLibraryName(String)}. * @return File indicating extracted resource on disk * @throws IOException if resource not found */ public static File extractFromResourcePath(String name) throws IOException { return extractFromResourcePath(name, null); }
private void extractJNI(Path jnaPath) throws IOException { URLClassLoader jnaLoader = new URLClassLoader(new URL[]{jnaPath.toUri().toURL()}); String libName = "/com/sun/jna/" + com.sun.jna.Platform.RESOURCE_PREFIX + '/' + System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib"); com.sun.jna.Native.extractFromResourcePath(libName, jnaLoader); }
private static void loadLibGmp() { try { // Explicitly try to load the embedded version first. File file = Native.extractFromResourcePath("gmp", LibGmp.class.getClassLoader()); load(file.getAbsolutePath()); return; } catch (Exception ignored) { } catch (UnsatisfiedLinkError ignored) { } // Fall back to system-wide search. load("gmp"); }
private static void loadLibGmp() { try { // Explicitly try to load the embedded version first. File file = Native.extractFromResourcePath("gmp", LibGmp.class.getClassLoader()); load(file.getAbsolutePath()); return; } catch (Exception ignored) { } catch (UnsatisfiedLinkError ignored) { } // Fall back to system-wide search. load("gmp"); }
try { String libName = "/com/sun/jna/" + Platform.RESOURCE_PREFIX + "/" + System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib"); File lib = extractFromResourcePath(libName, Native.class.getClassLoader()); if (lib == null) { if (lib == null) {
= Native.extractFromResourcePath( "/" + Platform.RESOURCE_PREFIX + "/" + libname, classLoader);
File embedded = Native.extractFromResourcePath(libraryName, (ClassLoader)options.get(Library.OPTION_CLASSLOADER)); try { handle = Native.open(embedded.getAbsolutePath(), openFlags);