解析java.library.path和LD_LIBRARY_PATH的介绍与区别

  static void loadLibrary(Class fromClass, String name,

  boolean isAbsolute) {

  ClassLoader loader =

  (fromClass == null) ? null : fromClass.getClassLoader();

  if (sys_paths == null) {

  usr_paths = initializePath("java.library.path");

  sys_paths = initializePath("sun.boot.library.path");

  }

  if (isAbsolute) {

  if (loadLibrary0(fromClass, new File(name))) {

  return;

  }

  throw new UnsatisfiedLinkError("Can't load library: " + name);

  }

  if (loader != null) {

  String libfilename = loader.findLibrary(name);

  if (libfilename != null) {

  File libfile = new File(libfilename);

  if (!libfile.isAbsolute()) {

  throw new UnsatisfiedLinkError(

  "ClassLoader.findLibrary failed to return an absolute path: " + libfilename);

  }

  if (loadLibrary0(fromClass, libfile)) {

  return;

  }

  throw new UnsatisfiedLinkError("Can't load " + libfilename);

  }

  }

  for (int i = 0 ; i < sys_paths.length ; i++) {

  File libfile = new File(sys_paths[i], System.mapLibraryName(name));

  if (loadLibrary0(fromClass, libfile)) {

  return;

  }

  }

  if (loader != null) {

  for (int i = 0 ; i < usr_paths.length ; i++) {

  File libfile = new File(usr_paths[i],

  System.mapLibraryName(name));

  if (loadLibrary0(fromClass, libfile)) {

  return;

  }

  }

  }

  // Oops, it failed

  throw new UnsatisfiedLinkError("no " + name + " in java.library.path");

  }