Using JavaCompiler in an OSGi Bundle

Deadly 提交于 2019-12-04 05:51:47

I've created a working example on GitHub.

It is not option 1 or 2, it creates a custom JavaFileManager which looks through all bundles and retrieves their resources.

Things to take into consideration:

  • It uses the JSR 199 compiler API, but it works only on the OpenJDK/Sun compiler, the Eclipse JDT compiler seems broken in this respect.
  • I've only tested on Equinox, I haven't used any equinox specific code, so it should work on other implementations.
  • It isn't optimized, so it might be slow and/or memory hungry.
  • It does register a bundle listener so it will flush its class cache when a bundle which offers a certain package resolves or unresolves
  • It is not very deterministic for split packages, I think.
  • It uses the BundleWiring API, which was introduced in OSGi 4.3, so it won't work on older OSGi implementations of OSGi (Karaf 2.x for example)

I should mention Technology Excruciation, his example helped me along tremendously.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!