You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Jacek Laskowski <ja...@laskowski.net.pl> on 2009/10/17 00:16:16 UTC

Q: JNDI context factory for OSGi env?

Hi,

I'm trying to figure out how to proceed with OSGi'fication of the
current openejb codebase and have created an ejb3 client that worked
fine standalone. When I run the client as a osgi bundle with
appropriate imports the client was not able to instantiate the
LocalInitialContextFactory (I believe it's java.lang.Class.forName
that messes it up). I guess it needs another approach for JNDI context
creation.

Does anybody know if there is another way to create a context so that
it's not javax.naming.spi.NamingManager.getInitialContext which
creates it, but some other code that would look for a service bundle
with the necessary context exposed as a service? Do you think that
javax.naming.spi.* package is the way to go?
InitialContextFactoryBuilder? Any help appreciated.

org.osgi.framework.BundleException: Activator start error in bundle
ejb_client [54].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1750)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1621)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:890)
        at org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:114)
        at org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:281)
        at org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:184)
        at java.lang.Thread.run(Thread.java:619)
Caused by: javax.naming.NoInitialContextException: Cannot instantiate
class: org.apache.openejb.client.LocalInitialContextFactory [Root
exception is java.lang.ClassNotFoundException: or
g.apache.openejb.client.LocalInitialContextFactory]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at ejb_client.Activator.start(Activator.java:23)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:667)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1699)
        ... 6 more
Caused by: java.lang.ClassNotFoundException:
org.apache.openejb.client.LocalInitialContextFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
        ... 12 more
javax.naming.NoInitialContextException: Cannot instantiate class:
org.apache.openejb.client.LocalInitialContextFactory [Root exception
is java.lang.ClassNotFoundException: org.apache.op
enejb.client.LocalInitialContextFactory]

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl

Re: Q: JNDI context factory for OSGi env?

Posted by Quintin Beukes <qu...@skywalk.co.za>.
Thanks for the update. Good to have these things in the back of your mind.

Quintin Beukes



On Mon, Oct 19, 2009 at 12:54 PM, Jacek Laskowski
<ja...@laskowski.net.pl> wrote:
> On Sat, Oct 17, 2009 at 12:16 AM, Jacek Laskowski
> <ja...@laskowski.net.pl> wrote:
>
>> I'm trying to figure out how to proceed with OSGi'fication of the
>> current openejb codebase and have created an ejb3 client that worked
>> fine standalone. When I run the client as a osgi bundle with
>> appropriate imports the client was not able to instantiate the
>> LocalInitialContextFactory (I believe it's java.lang.Class.forName
>> that messes it up). I guess it needs another approach for JNDI context
>> creation.
>
> Got it resolved. The necessary change in the client code was to link
> the current classloader with the thread's one.
>
> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
>
> It's one of the very well-known issues while migrating common java
> apps into OSGi env.
>
> Jacek
>
> --
> Jacek Laskowski
> Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl
>

Re: Q: JNDI context factory for OSGi env?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Sat, Oct 17, 2009 at 12:16 AM, Jacek Laskowski
<ja...@laskowski.net.pl> wrote:

> I'm trying to figure out how to proceed with OSGi'fication of the
> current openejb codebase and have created an ejb3 client that worked
> fine standalone. When I run the client as a osgi bundle with
> appropriate imports the client was not able to instantiate the
> LocalInitialContextFactory (I believe it's java.lang.Class.forName
> that messes it up). I guess it needs another approach for JNDI context
> creation.

Got it resolved. The necessary change in the client code was to link
the current classloader with the thread's one.

Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

It's one of the very well-known issues while migrating common java
apps into OSGi env.

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl