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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -