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.
See Question&Answers more detail:osIs 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.
See Question&Answers more detail:osThis 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.