1

I'm new to Web java programming. I want to create a simple JSF modular application. I found a simple tutorial link

but unfortunately I still have some questions how to use OSGI:

  1. Can I create a simple OGI bundle and place in it some JSF pages? If not how usually web applications are developed.
  2. Can you give me link with example how I can call functions and pass arguments form a WAR file to OSGI module.

Regards

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

4

Not an answer specifically for JSF (this might be), but for OSGi web-apps in general take a look at Pax-Web if you're using maven.

The easiest way to get started with Pax-Web is probably to use Karaf and then run the command features:install war

Once a WAR (or WAB - Web App Bundle) is deployed you'll be able to use the osgi-bundlecontext attribute in Servlet initialization, eg:

extends HttpServlet {

BundleContext bundleContext;

@Override
public void init() throws ServletException
{
    bundleContext = (BundleContext) getServletContext().getAttribute("osgi-bundlecontext");

}

Using this you can look up services in the OSGi registry.

You'll need to pay attention to the bundle's MANIFEST.MF entries, two in particular:

Bundle-ClassPath: ./,WEB-INF/classes
Webapp-Context: context-root-name-here

Or in an OSGi compliant WebApp container you'll need to add:

Web-ContextPath: context-root-name-here

There's more info in the specifications, see the enterprise or compendium PDFs for v4.2

EDIT: For deploying in JBoss you'll most likely want to use the WAB support, see section 128 of the enterprise 4.2 spec. Also this may help: http://community.jboss.org/message/619443 Interestingly JBoss AS7 is using pax-web, so the documentation for this should largely apply too.

Community
  • 1
  • 1
earcam
  • 6,662
  • 4
  • 37
  • 57
  • It turns out that I will use EAR packaging because I need to use resource adapter. Is above code compatible with EAR package? – Peter Penzov Dec 29 '11 at 09:42
  • I've edited my answer with some JBoss specific info, specifically you'll want to create a WAB (also added a link for maven-bundle-plugin) – earcam Dec 29 '11 at 11:10
  • One more question: I created a simple OSGI bundle which makes queries to database using datasource from JBoss 7.1.0. When I try to deploy it the JBoss 7.1.0 trows me an arror. Is it possible that this might be a bug in JBoss? – Peter Penzov Dec 29 '11 at 13:13
  • This is the error stack from JBoss when I try to deploy the OSGI bundle http://pastebin.com/XrCY6w5b – Peter Penzov Dec 29 '11 at 13:19
  • What for dependencies you are using for OSGI? – moohkooh Feb 05 '13 at 14:18