- 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.");
+ 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 of the library bundled into the jar file and use it */
+ loadLib(name);
+ } catch (SimGridLibNotFoundException e) {
+ /* If not found, try to see if we can find a version on disk */
+ try {
+ System.loadLibrary(name);
+ } catch (UnsatisfiedLinkError e2) {
+ System.err.println("Cannot load the bindings to the "+name+" library in path "+getPath());
+ e.printStackTrace();
+ System.err.println("This jar file does not seem to fit your system, and I cannot find an installation of SimGrid.");
+ System.exit(1);
+ }
+ }