Home > Mobile >  How to embed specific java modules into OSGi bundles? Is it even possible?
How to embed specific java modules into OSGi bundles? Is it even possible?

Time:09-21

Using java 11 , Eclipse, OSGi:

So, i have a "master" module in java. Basically, can be considered the main app module. From this module i dynamically access an OSGi implementation. (Right now, Apache felix, but it really shouldn't matter, i don't think.) I can then install/use OSGi bundles through that main app, and call on classes between the bundles if proper imports/exports are set. No problem.

My app module embeds the java.desktop and java.xml modules. Thus, all bundles i install have access to the classes within those modules (Swing, org.w3c.dom, etc.) -- and it works.

Now, what if i want to access code from a java module, say java.sql, from a new bundle, but i don't have that module (java.sql) embedded in my main module? How can that new bundle access the java.sql code?

Essentially, i get a class-not-found error every time i try to call on a module's code that i haven't first embedded in the main module. Via the Run Config i can set up my main module to embed those modules: java.desktop, java.xml, java.sql, or any others (via "requires" statements in the module-info file. How can i access new (non-currently-embedded) modules during runtime from later dynamically installed osgi bundles?

Is there some sort of bundle-config to embed specific java modules within a bundle, likening to the require statements in module-info?

Do i have to dynamically call on those new modules via some sort of service access?

Thanks much.

CodePudding user response:

Look at the OSGi Connect Specification and the Apache Felix Atomos project which implements OSGi Connect.

OSGi Connect defines mechanisms for mixed environments of JPMS modules and OSGi bundles to interact.

  • Related