Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading from JAR as an InputStream?

Is there a ClassLoader implementation I can use to load classes from an InputStream?

I'm trying to load a JAR for which I have an InputStream into a new ClassLoader.

like image 937
brabster Avatar asked Apr 10 '10 16:04

brabster


1 Answers

This is unlikely, as you will find if you try to do it yourself. You won't be able to randomly access an InputStream to look up classes as they're requested, so you'll have to cache the contents either in memory or in the file system.

If you cache on disk, just use URLClassLoader.

If you cache in memory, you'll need to create some sort of Map with JarInputStream and then extend ClassLoader (overriding the appropriate methods). The downside of this approach is that you keep data in RAM unnecessarily.

like image 138
McDowell Avatar answered Nov 09 '22 21:11

McDowell