Java: Jar Byte Array to Instantiated Object -



Java: Jar Byte Array to Instantiated Object -

i have byte array of jar file , want instantiate object defined class contained in jar. how this? right stuck at

inputstream inputstream = app.class.getresourceasstream("/example.jar"); byte[] bytes = ioutils.tobytearray(inputstream);

i think need 2 things, zip file reader , class loader. sound right direction?

you can utilize inbuilt urlclassloader resource path have , instantiate class. dont have read bytes yourself

// create urlclassloader urlclassloader urlclassloader = new urlclassloader(new url[]{new url("file://pathtojar/example.jar")}); class<?> lookupclass = urlclassloader.loadclass("com.somepackage.classname"); object inst = lookupclass.newinstance();

java jar classloader inputstream

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -