获取运行时生成的类的字节 [英] Get bytes for a class that was generated at runtime

查看:59
本文介绍了获取运行时生成的类的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Java框架,该框架使用自定义的ClassLoader在运行时生成一些(代理)类。我想从自定义ClassLoader从loadClass(..)返回的任何此类类中获取与该类相对应的原始字节数组。这可能吗?我知道,如果有一个类作为资源存在,那么您可以使用输入流以二进制格式加载该类,但是如果该类是在运行时生成的,该怎么办?

I am working with a Java framework that generates some (proxy) classes at runtime, using a custom ClassLoader. I would like to get for any such class that the custom ClassLoader returns from loadClass(..) the raw byte array that corresponds to this class. Is this possible? I know that if a class exists as a resource then you can use an input stream to load the class in binary format but how can I go about this if the class is generated at runtime?

推荐答案

注册 ClassFileTransformer 。记录所需的数据,而不是修改字节。

Register a ClassFileTransformer. Rather than modifying the bytes, record the data you need.

这篇关于获取运行时生成的类的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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