java - Custom class loader for loading dll in applet -


to address .dll file loading/unloading issue applets. loading, following this tutorial, .dll files using custom class loader :

1- class loader (copied tutorial)

public class customclassloader extends classloader {     private static final string class_name = customclassloader.class.getname();      private map<string, class<?>> classes;      public customclassloader() {         super(customclassloader.class.getclassloader());         classes = new hashmap<string, class<?>>();     }      public string tostring() {         return customclassloader.class.getname();     }      @override     public class<?> findclass(string name) throws classnotfoundexception {          if (classes.containskey(name)) {             return classes.get(name);         }          string path = name.replace('.', file.separatorchar) + ".class";         byte[] b = null;          try {             b = loadclassdata(path);         } catch (ioexception e) {             throw new classnotfoundexception("class not found @ path: " + new file(name).getabsolutepath(), e); **         }          class<?> c = defineclass(name, b, 0, b.length);         resolveclass(c);         classes.put(name, c);          return c;     }      private byte[] loadclassdata(string name) throws ioexception {         string methodname = class_name + ".loadclassdata";         byte buff[] = null;          try {             file file = new file(name);             int size = (int) file.length();             buff = new byte[size];             datainputstream in = new datainputstream(new fileinputstream(name));             in.readfully(buff);             in.close();          } catch (ioexception e) {             throw new ioexception(e.getmessage());         }         return buff;     } } 

2- class load .dll files

public class dllloader {      private static final string class_name = appletreload.class.getname();      static string javahome = system.getproperty("java.io.tmpdir");     private static string dllpath = javahome + constant.smartcard_jacspcsc_dll_name;     private static string dllpath1 = javahome + constant.smartcard_rxtxserial_dll_name;      public dllloader() {     }      static {         try {             system.load(dllpath);             logger.write(loggerconstant.trace, "jacspcsc dll loaded path: " + dllpath, "dll loader");             system.load(dllpath1);             logger.write(loggerconstant.trace, "rxtxserial dll loaded path: " + dllpath1, "dll loader");         } catch (exception e) {         // log exception;         }     } } 

and how using class loader:

cl = new customclassloader(); ca = cl.findclass("com.dllloader"); = ca.newinstance(); 

the motivation behind loading .dll using custom class loader guarantee unloading , of answers question on .dll loading/unloading suggest. in case, loadclassdata() (a function in classloader) thows exception:

   loadclassdata,error: com\dllloader.class (the system cannot find path specified)     java.io.filenotfoundexception: com\dllloader.class (the system cannot find path specified) 

and absolute path of file show logged as:

**c:\program files\mozilla firefox\com.dllloader

i think searching file, , .jar file of applet isn't located here.

i appreciate if can point out mistake making or tell how can guide browser class file in correct folder.

p.s: kindly note answer seemingly duplicate question don't solve problem.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -