On Sep 10, 2008, at 1:38 AM, Andreas Karalus wrote:

I want to test code that performs itself a "InitialContext ctx = new
InitialContext()". This works well with jboss.embedded, but fails with
openejb.
For jboss.embedded we use a jndi.properties as configuration. so if the file is present in classpath, new IntialContext() works fine. I wonder if there
is a similar configuration in openejb?
[...]

p.s. here is the data in jndi.properties

java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Right, it's the java.naming.factory.url.pkgs line that's causing the problem. A snippet from the InitialContext javadoc:

   JNDI determines each property's value by merging the values from
   the following two sources, in order:

   1. The first occurrence of the property from the constructor's
      environment parameter and (for appropriate properties) the
      applet parameters and system properties.

   2. The application resource files (jndi.properties).


The vm is picking JBoss's org.jboss.naming and org.jnp.interfaces packages for all "java:" lookups instead of ours because the values of the jndi.properties file are getting merged with your InitialContext properties.

You could either delete your jndi.properties file completely or you could update it as follows:

java .naming .factory.initial=org.apache.openejb.client.LocalInitialContextFactory
  java.naming.factory.url.pkgs=org.apache.openejb.core.ivm.naming


Just make sure that you don't use these settings in an actual remote client running in a different VM than the server. There you'd use these settings:

java .naming .factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
  java.naming.factory.url.pkgs=org.apache.openejb.client


-David



Reply via email to