I have a signed applet and I want to write out dll files which are contained in the jar from which I launch my applet.
I am doing this because I then want to do a System.load on the dll's, as apparently you can't load DLL's from inside a jar in an applet.
The second issue is if you can add to the environment variables in an applet - for example I want to extract my DLL's to a location the hard drive and add the environment variable so System.load can find it.
You should be able to accomplish this by:
.dll
from the applet jar into the system temporary directory.System.load(..)
on the extracted file with AccessController
.This approach would avoid the need to set an environment variable. Here's some example code:
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
String dllName = "my.dll";
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File tmpFile = new File(tmpDir, dllName);
try {
InputStream in = getClass().getResourceAsStream(dllName);
OutputStream out = new FileOutputStream(tmpFile);
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.load(tmpFile.getAbsolutePath());
} catch (Exception e) {
// deal with exception
}
return null;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With