- public static String getPath() {
- String prefix = "NATIVE";
- String os = System.getProperty("os.name");
- String arch = System.getProperty("os.arch");
-
- if (arch.matches("^i[3-6]86$"))
- arch = "x86";
- else if (arch.equalsIgnoreCase("amd64"))
- arch = "x86_64";
-
- if (os.toLowerCase().startsWith("win")){
- os = "Windows";
- arch = "x86";
- }else if (os.contains("OS X"))
- os = "Darwin";
-
- os = os.replace(' ', '_');
- arch = arch.replace(' ', '_');
-
- return prefix + "/" + os + "/" + arch + "/";
- }
- public static void nativeInit(String name) {
- try {
- /* prefer the version on disk, if existing */
- System.loadLibrary(name);
- } catch (UnsatisfiedLinkError e) {
- /* If not found, unpack the one bundled into the jar file and use it */
- loadLib(name);
- }
- }
-
- private static void loadLib (String name) {
- String Path = NativeLib.getPath();
-
- String filename=name;
- InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
-
- if (in == null) {
- filename = "lib"+name+".so";
- in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = name+".dll";
- in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = "lib"+name+".dll";
- in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = "lib"+name+".dylib";
- in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- throw new RuntimeException("Cannot find library "+name+" in path "+Path+". Sorry, but this jar does not seem to be usable on your machine.");