Question

Background

I am embedding an OSGi runtime based on Apache Felix in the bridged mode in a Tomcat6 container. There are a bunch of JDBC connections specified in the conf/server.xml file in Tomcat6.

<Resource name="foo/bar" ... />

Question

The standard JNDI lookup doesn't seem to work from bundles deployed to the OSGi container.

ctx.lookup("java:comp/env/foo/bar");

Is there anything special that needs to be done for the OSGi runtime to be able to lookup resources registered in the parent Tomcat6 container?

Was it helpful?

Solution

@Martin's comment got me thinking about multiple threads part. I got this to work by:

  1. Ensuring that ctx.lookup(...) is invoked in the BundleActivator. This is because, in the bridged mode, the ClassLoader of the thread running the Activator code can look up all Classes and Resources that are defined in the parent WAR file.
  2. Ensuring that the parent WAR's META-INF/context.xml exposes the JNDI resource via <ResourceLink global="foo/bar" name="foo/bar" type="javax.sql.DataSource"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top