Hi,

it looks like for me like you are having some jndi and classpath  problems,
take a look if you still have some jboss specific jndi.properties.

java.naming.factory.url.pkgs org.jboss.naming:org.jnp.interfaces

anyway I found a simple way to bind a datasource in jboss specific style(we
are using jboss in production and  openejb in junit tests). You can try
something  like this

p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
        p.put("java:/movieDatabase", "new://Resource?type=DataSource");
        p.put("java:/movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("java:/movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

        Context context = new InitialContext(p);


-> context.lookup("java:/movieDatabase") should then work ... 

regards,
andreas


Mangan wrote:
> 
> Hi!
> 
> I recentally started using OpenEJB for doing unit testing with JUnit. I've
> got it to work for everything I've tried so far but now I've run into some
> problems: 
> 
> When trying to unit test a method, that in a lower layer uses a database
> connection, I get an error. 
> 
> java.lang.NoClassDefFoundError: org/jnp/server/NamingServer
>       at
> org.jboss.naming.java.javaURLContextFactory.<clinit>(javaURLContextFactory.java:52)
>       at java.lang.Class.forName0(Native Method)
>       at java.lang.Class.forName(Class.java:242)
>       at
> com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:50)
>       at
> com.sun.naming.internal.ResourceManager.getFactory(ResourceManager.java:371)
>       ...
> Code for lookup:
> try{
>       InitialContext ctx = new InitialContext();
>       DataSource ds = (DataSource) ctx.lookup( "java:/MyDataSource");
>       return ds.getConnection();
> }
> // If we arn't in a JBoss context, 
> catch ( NamingException ne){
>       throw new RuntimeException("NamingException while getting a JDBC
> connection");
> }
> 
> This does not suprise me because I've read some posts about problems when
> using a JBoss-style lookup on datasources ("java:/DataSourceName"). In my
> inital tests I've got the datasource configured in the open-ejb.xml and
> the connection to work via annotations. So I know my datasource works. I
> would gladly change my datasource lookups in the future when using JBoss
> (if it's possible) but the projekt I'm working on now is huge so that's
> not really an option.
> 
> Is there some way to setup the datasource to be able to use JBoss-style
> lookups?
> 
> Or, am I mistaken in my assumption that this have anything to do with the
> datasource lookup?
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Configure-datasource-to-work-with-JBoss-style-lookups--tp19720947p19733194.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to