From 39911230734de0b610f3243f3fb519688f9ae399 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Tue, 27 Jan 2015 20:05:04 -0500 Subject: [PATCH] NativeLibraryLoader: Don't load LWJGL / JInput when they are not found in classpath * LWJGL / JInput have their own loading mechanism which works fine when they are in java.library.path (e.g. when bundling) --- .../com/jme3/system/NativeLibraryLoader.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index 1ea33fd5e..f23273257 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -316,6 +316,32 @@ public final class NativeLibraryLoader { } } + /** + * Removes platform-specific portions of a library file name so + * that it can be accepted by {@link System#loadLibrary(java.lang.String) }. + *

+ * E.g.
+ *

+ * + * @param filename The filename to strip platform-specific parts + * @return The stripped library name + */ + private static String unmapLibraryName(String filename) { + StringBuilder sb = new StringBuilder(filename); + if (sb.indexOf("lib") == 0 && !filename.toLowerCase().endsWith(".dll")) { + sb.delete(0, 3); + } + int dot = sb.lastIndexOf("."); + if (dot > 0) { + sb.delete(dot, sb.length()); + } + return sb.toString(); + } + public static File getJarForNativeLibrary(Platform platform, String name) { NativeLibrary library = nativeLibraryMap.get(new NativeLibrary.Key(name, platform)); if (library == null) { @@ -482,21 +508,27 @@ public final class NativeLibraryLoader { if (url == null) { // Attempt to load it as a system library. + String unmappedName = unmapLibraryName(fileNameInJar); try { - System.loadLibrary(name); - logger.log(Level.FINE, "Loaded system installed " + - "version of native library: {0}", name); + // XXX: HACK. Vary loading method based on library name.. + // lwjgl and jinput handle loading by themselves. + if (!name.equals("lwjgl") && !name.equals("jinput")) { + // Need to unmap it from library specific parts. + System.loadLibrary(unmappedName); + logger.log(Level.FINE, "Loaded system installed " + + "version of native library: {0}", unmappedName); + } } catch (UnsatisfiedLinkError e) { if (isRequired) { throw new UnsatisfiedLinkError( - "The required native library '" + name + "'" + "The required native library '" + unmappedName + "'" + " was not found in the classpath via '" + pathInJar + "'. Error message: " + e.getMessage()); } else { logger.log(Level.FINE, "The optional native library ''{0}''" + " was not found in the classpath via ''{1}''" + ". Error message: {2}", - new Object[]{name, pathInJar, e.getMessage()}); + new Object[]{unmappedName, pathInJar, e.getMessage()}); } }