使用OSGi时可以进行字节码操作吗? [英] Is it possible to do bytecode manipulation when using OSGi?

查看:106
本文介绍了使用OSGi时可以进行字节码操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作应用服务器,在其中我需要使用一些字节码操作(例如,插入自定义equalshashCode方法,以用@Entity注释的类).现在,我为JVM提供了Java代理( -javaagent 选项)使用 ASM 进行字节码转换.

I'm making an application server and in it I need to use some bytecode manipulation (e.g. inserting custom equals and hashCode methods to classes annotated with @Entity). Now I give the JVM a Java Agent (the -javaagent option) which does bytecode transformations using ASM.

我一直在考虑使用 OSGi ,但我不知道它是否允许我进行必要的字节码操作.

I've been considering using OSGi, but I don't know whether it allows me to do the necessary bytecode manipulation.

  1. 使用OSGi时可以进行字节码操作吗?怎么样?
  2. 捆绑软件是否可以声明自身,是否需要某种字节码操作才能使其工作?例如,应用程序服务器要求操纵其某些核心类.
  3. 是否可以指定其他捆绑软件需要某些字节码操作,而该捆绑软件却不知道呢?例如,必须对服务器上运行的所有应用程序进行操作,但这些应用程序不需要了解它.
  4. 一个包是否可以声明自己,依赖它的所有包都必须进行字节码处理?这使我很容易声明所有依赖包含@Entity批注的API捆绑包的人都必须受到操纵.
  1. Is it possible to do bytecode manipulation when using OSGi? How?
  2. Is it possible for a bundle to declare itself, that it requires some bytecode manipulation for it to work? For example the application server requires that some of its own core classes are manipulated.
  3. Is it possible to specify that some other bundle requires some bytecode manipulation, without that bundle knowing about it? For example all applications which run on the server must be manipulated, but the applications don't need to know about it.
  4. Is it possible for a bundle to declare itself, that all bundles which depend on it must be bytecode manipulated? This would make it easy for me to declare that all who depend on the API bundle which contains the @Entity annotation, must be manipulated.

推荐答案

OSGI 4.3添加了 WeavingHook 允许您使用所选的字节码操纵器进行字节码操纵.我在一个项目中将它与JavaAssist一起使用,效果很好.

OSGI 4.3 added the WeavingHook which allows you to do byte code manipulation with a byte code manipulator of your choice. I use it with JavaAssist on one of my projects and it works great.

这篇关于使用OSGi时可以进行字节码操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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