1

After exploring the OSGi framework, I had developed a sample web application.The Web Application Bundle(.war or .jar) is packaged inside an eba. The war file contains a bunch of embedded jar files in its WEB-INF/lib directory.These jars have been converted to OSGi bundles(using maven-bundle-plugin) with the required export and import packages as per the relation between the jars. Now I have to even mention all these jars(WEB-INF/lib) in the bundle-classpath. The above works because a bundle(wab is also a bundle) can include one or more jarfiles within it, and use a Bundle-Classpath manifest.mf entry to point to them.

Incase I dont include the jars in the bundle-classpath I get a ClassNotFoundException.

The question is,then there's no point converting the jars to osgi bundles.Obviously all the jars in the WEB-INF/lib are loaded by the same class loader(i.e wab's class loader) ,so then we are not reaping the major benefits of OSGi which is mainly a per bundle classloader concept?

Salman S
  • 47
  • 1
  • 15
crackerplace
  • 5,305
  • 8
  • 34
  • 42
  • Sounds right, if you have a war with a deployment descriptor then that belongs in a jee container like tomcat etc. You are not really using OSGi as intended with a war containing its own "lib" – codesalsa Mar 21 '14 at 20:28
  • @codesalsa Initially I assumed the jars in the lib folder would also get deployed as bundles as they have the OSGi specific Manifest Entry's.But they are treated just as normal jars as mentioned in the wab bundle's classpath. – crackerplace Mar 21 '14 at 20:46
  • not sure then whats the use of converting web application to osgi assuming that I don't need the services registry of OSGI.Ofcourse we cannot manually install each of the bundles from the lib folder. – crackerplace Mar 21 '14 at 20:47

1 Answers1

1

Putting jars inside the WEB-INF/lib is the old-style normal-java way of handling dependencies, and putting them outside the war is the new-style OSGi way of handling them.

By packaging your war's dependencies in WEB-INF/lib, you're treating them as normal jars (remember a bundle is also a jar). So in that case, you're right that there wasn't much point in using bundles.

One of the benefits of using wabs instead of wars is to get away from the dreaded 100 Mb monolithic war. Rather than packaging the bundles inside WEB-INF/lib, try having the war import the packages it needs using Import-Package:, and package the dependencies inside the eba. (If you don't remember to have the war import the packages it needs, you'll get the class not found exceptions you were seeing, because the OSGi container won't know your war needs those packages.)

Holly Cummins
  • 10,767
  • 3
  • 23
  • 25
  • ok,so you mean wab and the bundles from the WEB-INF/lib should be at the same level i.e one step inside the eba so that the jars(with OSGi Manifest) which were inside WEB-INF/lib also are installed as bundles. Ex : enterprise.eba(META-INF,webapp.wab,util.jar etc).Yes the imports at the war level are required as now there are no jars inside the war and the bundle-classpath is empty. – crackerplace Mar 22 '14 at 10:09
  • Yes, that's exactly right. If you wanted, you could also move the jars up a further level, to the same level as the eba, so they can be share between different ebas. – Holly Cummins Mar 23 '14 at 06:21
  • Packing in an EBA is the easy way out as we need to just deploy it at one go.Also,these bundles are specific to an application so they are not common kind of and their place in an eba helps.As we use Websphere,moving the bundles up one level,would be a huge effort as installing the 30-40 bundles one by one would be a hectic task unless there are automated solutions which can be scripted. – crackerplace Mar 23 '14 at 15:05
  • We will anywayz move the 2 or 3 common modules and register them as services. – crackerplace Mar 23 '14 at 15:06