tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Karalus <>
Subject Re: Configure datasource to work with JBoss style lookups?
Date Mon, 29 Sep 2008 22:46:30 GMT


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

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("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 ... 


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
> 	at java.lang.Class.forName0(Native Method)
> 	at java.lang.Class.forName(
> 	at
> com.sun.naming.internal.VersionHelper12.loadClass(
> 	at
> com.sun.naming.internal.ResourceManager.getFactory(
> 	...
> 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:
Sent from the OpenEJB User mailing list archive at

View raw message