I'm working with JBOSS AS 7.1.1. I have registered a datasource and I try to access it throught a JNDI in my OSGI bundle like :
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(datasource_jndi_name);
but when i deploy my bundle to AS i get an exception: ClassNotFoundException: javax.naming.Context.
Context is defined in rt.jar, so i tried to wrap it in bundle and deploy it to AS but got the same error.
I tried to replace Context with InitialContext and got ClassNotFoundException: javax.naming.InitialContext.
Yepp, OSGi isolates that away. You an Import-Package
for javax.naming
. In addition you should probably use JNDIContextManager#newInitialContext()
to create the initial context.