diff -up ./src/com/sun/jna/Native.java.loadlib ./src/com/sun/jna/Native.java --- ./src/com/sun/jna/Native.java.loadlib 2012-03-07 11:41:53.378594071 +0100 +++ ./src/com/sun/jna/Native.java 2012-03-07 11:52:18.537721064 +0100 @@ -634,148 +634,18 @@ public final class Native { /** * Loads the JNA stub library. - * First tries jna.boot.library.path, then the system path, then from the - * jar file. + * MODIFIED FROM UPSTREAM - we rip out all sorts of gunk here that is + * unnecessary when JNA is properly installed with the OS. */ private static void loadNativeLibrary() { removeTemporaryFiles(); - String libName = System.getProperty("jna.boot.library.name", "jnidispatch"); - String bootPath = System.getProperty("jna.boot.library.path"); - if (bootPath != null) { - // String.split not available in 1.4 - StringTokenizer dirs = new StringTokenizer(bootPath, File.pathSeparator); - while (dirs.hasMoreTokens()) { - String dir = dirs.nextToken(); - File file = new File(new File(dir), System.mapLibraryName(libName)); - String path = file.getAbsolutePath(); - if (file.exists()) { - try { - System.load(path); - nativeLibraryPath = path; - return; - } catch (UnsatisfiedLinkError ex) { - // Not a problem if already loaded in anoteher class loader - // Unfortunately we can't distinguish the difference... - //System.out.println("File found at " + file + " but not loadable: " + ex.getMessage()); - } - } - if (Platform.isMac()) { - String orig, ext; - if (path.endsWith("dylib")) { - orig = "dylib"; - ext = "jnilib"; - } else { - orig = "jnilib"; - ext = "dylib"; - } - path = path.substring(0, path.lastIndexOf(orig)) + ext; - if (new File(path).exists()) { - try { - System.load(path); - nativeLibraryPath = path; - return; - } catch (UnsatisfiedLinkError ex) { - System.err.println("File found at " + path + " but not loadable: " + ex.getMessage()); - } - } - } - } - } try { - if (!Boolean.getBoolean("jna.nosys")) { - System.loadLibrary(libName); - return; - } + System.load("@JNIPATH@/" + System.mapLibraryName("jnidispatch")); + nativeLibraryPath = "@JNIPATH@/" + System.mapLibraryName("jnidispatch"); } catch(UnsatisfiedLinkError e) { - if (Boolean.getBoolean("jna.nounpack")) { - throw e; - } - } - if (!Boolean.getBoolean("jna.nounpack")) { - loadNativeLibraryFromJar(); - return; - } - throw new UnsatisfiedLinkError("Native jnidispatch library not found"); - } - - /** - * Attempts to load the native library resource from the filesystem, - * extracting the JNA stub library from jna.jar if not already available. - */ - private static void loadNativeLibraryFromJar() { - String libname = System.mapLibraryName("jnidispatch"); - String arch = System.getProperty("os.arch"); - String name = System.getProperty("os.name"); - String resourceName = getNativeLibraryResourcePath(Platform.getOSType(), arch, name) + "/" + libname; - URL url = Native.class.getResource(resourceName); - boolean unpacked = false; - - // Add an ugly hack for OpenJDK (soylatte) - JNI libs use the usual - // .dylib extension - if (url == null && Platform.isMac() - && resourceName.endsWith(".dylib")) { - resourceName = resourceName.substring(0, resourceName.lastIndexOf(".dylib")) + ".jnilib"; - url = Native.class.getResource(resourceName); - } - if (url == null) { - throw new UnsatisfiedLinkError("jnidispatch (" + resourceName - + ") not found in resource path"); - } - - File lib = null; - if (url.getProtocol().toLowerCase().equals("file")) { - try { - lib = new File(new URI(url.toString())); - } - catch(URISyntaxException e) { - lib = new File(url.getPath()); - } - if (!lib.exists()) { - throw new Error("File URL " + url + " could not be properly decoded"); - } - } - else { - InputStream is = Native.class.getResourceAsStream(resourceName); - if (is == null) { - throw new Error("Can't obtain jnidispatch InputStream"); - } - - FileOutputStream fos = null; - try { - // Suffix is required on windows, or library fails to load - // Let Java pick the suffix, except on windows, to avoid - // problems with Web Start. - File dir = getTempDir(); - lib = File.createTempFile("jna", Platform.isWindows()?".dll":null, dir); - lib.deleteOnExit(); - fos = new FileOutputStream(lib); - int count; - byte[] buf = new byte[1024]; - while ((count = is.read(buf, 0, buf.length)) > 0) { - fos.write(buf, 0, count); - } - unpacked = true; - } - catch(IOException e) { - throw new Error("Failed to create temporary file for jnidispatch library: " + e); - } - finally { - try { is.close(); } catch(IOException e) { } - if (fos != null) { - try { fos.close(); } catch(IOException e) { } - } - } - } - System.load(lib.getAbsolutePath()); - nativeLibraryPath = lib.getAbsolutePath(); - // Attempt to delete immediately once jnidispatch is successfully - // loaded. This avoids the complexity of trying to do so on "exit", - // which point can vary under different circumstances (native - // compilation, dynamically loaded modules, normal application, etc). - if (unpacked) { - deleteNativeLibrary(lib.getAbsolutePath()); + throw new RuntimeException(e); } }