How to load classes from jar file in-memory stream

2019-02-26 13:19发布

问题:

I'm building a Java application that has parts that require daily update. I want to download frequently updated parts as small jar file from my server to memory. I'm downloading the jar file as byte stream and not using URLClassloader.

  1. How can I make the classes in the jar file to be available to the system class loader from my custom class loader?

  2. How can I make sure that the download jar file and loaded classes are never cached or written to disk.

回答1:

You can have a custom class loader load from memory. You can force the system loader, load specified classes from memory. However, you can't change the default system loader to read from memory on the fly.