如何从jar文件内存中加载类 [英] How to load classes from jar file in-memory stream

查看:518
本文介绍了如何从jar文件内存中加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Java应用程序,其中包含需要每日更新的部分。我想将经常更新的零件作为小jar文件从我的服务器下载到内存。我正在下载jar文件作为字节流,而不是使用URLClassloader。

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. 如何使jar文件中的类为
    从系统类加载器类加载器?

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

如何确保下载的jar文件和加载的类不会被缓存或写入磁盘。

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


推荐答案

您可以从内存中加载自定义类加载器。你可以强制系统加载器,从内存加载指定的类。但是,您无法更改默认系统加载程序以便即时从内存中读取。

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.

这篇关于如何从jar文件内存中加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆