예제 #1
0
 private static String nativeLibraryName(String baseName) {
   Platform platform = Platform.getPlatform();
   if (platform.isSolaris() || platform.isLinux()) {
     return "lib" + baseName + ".so";
   } else if (platform.isMac()) {
     return "lib" + baseName + ".dylib";
   } else if (platform.isWindows()) {
     return baseName; // + ".dll";
   } else {
     return baseName;
   }
 }
예제 #2
0
  static {
    String webstartPath = Native.getWebStartLibraryPath("jnidispatch");
    if (webstartPath != null) {
      librarySearchPath.add(webstartPath);
    }
    if (System.getProperty("jna.platform.library.path") == null && !Platform.isWindows()) {
      // Add default path lookups for unix-like systems
      String platformPath = "";
      String sep = "";
      String archPath = "";

      //
      // Search first for an arch specific path if one exists, but always
      // include the generic paths if they exist.
      // NOTES (wmeissner):
      // Some older linux amd64 distros did not have /usr/lib64, and
      // 32bit distros only have /usr/lib.  FreeBSD also only has
      // /usr/lib by default, with /usr/lib32 for 32bit compat.
      // Solaris seems to have both, but defaults to 32bit userland even
      // on 64bit machines, so we have to explicitly search the 64bit
      // one when running a 64bit JVM.
      //
      if (Platform.isLinux()
          || Platform.isSolaris()
          || Platform.isFreeBSD()
          || Platform.iskFreeBSD()) {
        // Linux & FreeBSD use /usr/lib32, solaris uses /usr/lib/32
        archPath = (Platform.isSolaris() ? "/" : "") + Pointer.SIZE * 8;
      }
      String[] paths = {
        "/usr/lib" + archPath, "/lib" + archPath, "/usr/lib", "/lib",
      };
      // Multi-arch support on Ubuntu (and other
      // multi-arch distributions)
      // paths is scanned against real directory
      // so for platforms which are not multi-arch
      // this should continue to work.
      if (Platform.isLinux() || Platform.iskFreeBSD() || Platform.isGNU()) {
        String multiArchPath = getMultiArchPath();

        // Assemble path with all possible options
        paths =
            new String[] {
              "/usr/lib/" + multiArchPath,
              "/lib/" + multiArchPath,
              "/usr/lib" + archPath,
              "/lib" + archPath,
              "/usr/lib",
              "/lib",
            };
      }
      for (int i = 0; i < paths.length; i++) {
        File dir = new File(paths[i]);
        if (dir.exists() && dir.isDirectory()) {
          platformPath += sep + paths[i];
          sep = File.pathSeparator;
        }
      }
      if (!"".equals(platformPath)) {
        System.setProperty("jna.platform.library.path", platformPath);
      }
    }
    librarySearchPath.addAll(initPaths("jna.platform.library.path"));
  }