简体   繁体   中英

Can you have JSF custom components in different OSGi bundles?

Has anyone used OSGi and JSF together?

I ask because JSF uses class-loader magic to find custom components. From a tutorial (emphasis mine):

This configuration file will end up being META-INF/faces-config.xml in the .jar file that represents this component. JSF will look for such a file name in each of the .jar files that are loaded at runtime (in the WEB-INF/lib directory for .war files) and use each of them in its configuration. In this way, multiple component .jar files can be combined into one web application, and all of the components described in each .jar will be available to the application.

I would like to be able to have JSF custom components as OSGi bundles (ie custom components are in different OSGi bundles than the JSF runtime) and for JSF to be able to find these at runtime.

Has anyone done anything similar?

I am not sure it does exactly answer your problem, but I found this thread about Spring and osgi interresting, especially thisspecific answer where dependencies and classpath are bundled in the MANIFEST.MF.

That thread also leads to the update of this for tutorial about Spring Dynamic Modules (DM) for OSGi™ Service Platforms which may also be of interest.

It is possible in the following way:

  • Your web osgi bundle has to have "Require-Bundle" in MANIFEST.MF pointing to the bundle that contains the components
  • Your component jar has to have Export-Package containing META-INF and subpackages of META-INF where there is any JSF related file (and of course standard packages of the component). For example: Export-Package: META-INF,META-INF.resources...

If you use maven-bundle plugin you must use an apostrophe and an equal for exporting META-INF and sub-packages. For example:

<Export-Package>
  a.b.c,
  '=META-INF',
  '=META-INF.resources',
  ...
</Export-Package>

In JSF Spec 2.2 there might be parts about JSF-OSGI relationship. To see the progress see http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-942

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM