0

In a specific point in my deployed OSGi bundle, I get a jar file URI in OSGi standard format, jar file that I need to parse for entity classes. So, having the URI like: bundle://233.0:1, would it be possible to get the jar file so that, I will be able to parse it for what kind of entity it has?

Note: I'm trying to solve an issue that I have with OpenJPA, Apache Servicemix and Spring Framework.

If you need any further clarifications, ask me please.

рüффп
  • 5,172
  • 34
  • 67
  • 113
artaxerxe
  • 6,281
  • 21
  • 68
  • 106

1 Answers1

2

You do not need the jar. You can query the entries of a bundle with the following functions:

First one returns only entries that is available in the bundle directly. Second one returns entries from the bundle and its fragments. Third one returns entries that the bundle's classloader sees (entries of the bundle, its fragments and entries from imported packages)

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • Nice answer. Additionally, the bundle may not even map to a file on the filesystem at all. Making assumptions about this kind of thing is a good way to make non-portable, fragile code. – Neil Bartlett Jul 23 '14 at 20:22
  • The first number is the id of the bundle but I do not know if this URI is really a standard format or it is a speciality of the container that you use. If you have the classloader or a class from the jar, you can get the bundle. See the source code of FrameworkUtil.getBundle(Class>);. It is very easy to read. However, the best would be if you could refactor your code in the way that instead of getting an URI / classLoader, you get the bundle instance. Somewhere deep, there must be a BundleTracker that knows the bundle instance and calls your code. – Balazs Zsoldos Jul 24 '14 at 07:29
  • "How to get the bundle that my URI points to" < well, the interesting question is, how did you get that URI? – Neil Bartlett Jul 24 '14 at 08:38
  • @NeilBartlett I really don't know. I'm working on *OpenJPA* source code. And I need to make it to load entities from bundle. So, to have an answer to your question, I would need to dig more on *Spring* or *OpenJPA* source code. :) – artaxerxe Jul 24 '14 at 09:00
  • @artaxerxe Err... okay. So, Spring or OpenJPA gave you this URI somehow? Sounds weird. – Neil Bartlett Jul 24 '14 at 09:28
  • @NeilBartlett *OpenJPA*. Only that I use it in conjunction with *Spring*, so it can be possible this comes from *Spring*. – artaxerxe Jul 24 '14 at 09:57
  • Off: @artaxerxe: If Spring uses such tricks that on the end you get this URI, I suggest you to choose either Spring+JPA+JSF+... or OSGi world. If you are commited to the old technology stack due to previous projects, this can be a long term strategy. E.g.: After a long investigation we replaced JPA with Querydsl + Liquibase. Since that we have not met issues that come from tricky solutions (In my opinion the L1, L2 cache and entity objects with their lifecycles are delusive inventions that should be avoided). If you choose OSGi, choose technologies that do not want to be smarter than you. – Balazs Zsoldos Jul 24 '14 at 10:37