Login  Register

Re: JOGL TempJarCache natives jars already in classpath

Posted by sam on Aug 14, 2013; 12:55pm
URL: https://forum.jogamp.org/JOGL-TempJarCache-natives-jars-already-in-classpath-tp4029804p4029807.html

Hi,

I fully understand that JOGL can't test every possible convention.

Inspired by your idea just to put the native libraries side by side to the jars. I manually extract the native libraries from the included jars right before I initialize jogl

private void extractJOGLLibraries() {
	final File dir = new File(".");
	ClassLoader classLoader = SandBoxLauncher.class.getClassLoader();
	for(String lib : Arrays.asList("gluegen-rt","jogl_desktop","jogl_mobile","nativewindow_awt","nativewindow_win32","newt") ) {
		String nativeLib = System.mapLibraryName(lib);
		File file = new File(dir,nativeLib);
		try (InputStream in = classLoader.getResourceAsStream(nativeLib);
				OutputStream to = new BufferedOutputStream(new FileOutputStream(file))) {
			ByteStreams.copy(in, to);
		} catch (IOException e) {
			System.err.println("can't extract: " + nativeLib);
			e.printStackTrace();
		}
		file.deleteOnExit();
	}
}