1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| // 1. Determine the OS we're running on and make a native library name
// from that.
String osName = System.getProperty("os.name"), nativeLibName1 = null, nativeLibName2 = null, nativeLibName3 = null, nativeLibName4 = null;
if (osName.equals("Windows")) {
nativeLibName1 = "jogl.dll";
nativeLibName2 = "gluegen-rt.dll";
nativeLibName3 = "jogl_cg.dll";
nativeLibName4 = "jogl_awt.dll";
System.out.println("Systeme Windows detecte.");
} else if (osName.equals("Linux")) {
nativeLibName1 = "libjogl.so";
nativeLibName2 = "libgluegen-rt.so";
nativeLibName3 = "libjogl_cg.so";
nativeLibName4 = "libjogl_awt.so";
System.out.println("Systeme GNU/Linux detecte.");
} else if (osName.equals("MacOS")) {
nativeLibName1 = "libjogl.jnilib";
nativeLibName2 = "libgluegen-rt.jnilib";
nativeLibName3 = "libjogl_cg.jnilib";
nativeLibName4 = "libjogl_awt.jnilib";
System.out.println("Systeme MacOS detecte.");
} else {
System.out.println("Votre systeme n'est pas supporte.");
System.exit(1);
}
try {
// 2. Write this library to a file. Windows: Documents and
// Settings\\username; Linux: /home/username
InputStream nativeLibIn1 = new FileInputStream(new File("libs/"
+ nativeLibName1));
InputStream nativeLibIn2 = new FileInputStream(new File("libs/"
+ nativeLibName2));
InputStream nativeLibIn3 = new FileInputStream(new File("libs/"
+ nativeLibName1));
InputStream nativeLibIn4 = new FileInputStream(new File("libs/"
+ nativeLibName2));
System.out.println(nativeLibName1);
System.out.println(nativeLibName2);
System.out.println(nativeLibName3);
System.out.println(nativeLibName4);
File nativeLib1 = new File(System.getProperty("user.home"),
nativeLibName1);
File nativeLib2 = new File(System.getProperty("user.home"),
nativeLibName2);
File nativeLib3 = new File(System.getProperty("user.home"),
nativeLibName1);
File nativeLib4 = new File(System.getProperty("user.home"),
nativeLibName2);
OutputStream nativeLibOut1 = new FileOutputStream(nativeLib1);
OutputStream nativeLibOut2 = new FileOutputStream(nativeLib2);
OutputStream nativeLibOut3 = new FileOutputStream(nativeLib3);
OutputStream nativeLibOut4 = new FileOutputStream(nativeLib4);
int readBytes1;
int readBytes2;
int readBytes3;
int readBytes4;
byte[] buffer1 = new byte[4096];
byte[] buffer2 = new byte[4096];
byte[] buffer3 = new byte[4096];
byte[] buffer4 = new byte[4096];
while ((readBytes1 = nativeLibIn1.read(buffer1)) > 0)
nativeLibOut1.write(buffer1, 0, readBytes1);
while ((readBytes2 = nativeLibIn2.read(buffer2)) > 0)
nativeLibOut2.write(buffer2, 0, readBytes2);
while ((readBytes3 = nativeLibIn3.read(buffer3)) > 0)
nativeLibOut3.write(buffer3, 0, readBytes3);
while ((readBytes4 = nativeLibIn4.read(buffer4)) > 0)
nativeLibOut4.write(buffer4, 0, readBytes4);
// 3. Load JOGL. System.load requires an absolute path.
System.load(nativeLib1.toString());
System.load(nativeLib2.toString());
System.load(nativeLib3.toString());
System.load(nativeLib4.toString());
} catch (IOException ioe) {
System.out.println("Erreur de chargement des libraires natives.\n");
ioe.printStackTrace();
} |
Partager