ufis
November 20th, 2008, 12:00 PM
I am trying to access a (websphere) DataSource from a standalone java application via jndi.
I have a url for the datasource: jndi://someserver:12345/path/to/datasource
All examples point to code similar to this:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jndi://someserver:12345/path/to/datasource");
But I get the exception: javax.naming.NoInitialContextException when doing ctx.lookup()
From scratching around it looks like this is caused by a ClassNotFoundException, looking for com.sun.jndi.url.jndi.jndiURLContextFactory.
After some reading I found that java (I am using sun 1.6) does not have a jndiURLContextFactory to enable it to handle the jndi:// address. It has context factories for ldap and corba and some others, but no jndi.
Google for jndiURLContextFactory brings up an Apache project that seems to dormant with no source in their svn repository for this.
So I am lost. Am I even on the right path?
I need to access this DataSource from a standalone java app (run with java -jar Myjar.jar). In fact I need to access a couple DataSources from this app.
What do I need from the server side (other than the url)?
What do I need to do on my side?
I have a url for the datasource: jndi://someserver:12345/path/to/datasource
All examples point to code similar to this:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jndi://someserver:12345/path/to/datasource");
But I get the exception: javax.naming.NoInitialContextException when doing ctx.lookup()
From scratching around it looks like this is caused by a ClassNotFoundException, looking for com.sun.jndi.url.jndi.jndiURLContextFactory.
After some reading I found that java (I am using sun 1.6) does not have a jndiURLContextFactory to enable it to handle the jndi:// address. It has context factories for ldap and corba and some others, but no jndi.
Google for jndiURLContextFactory brings up an Apache project that seems to dormant with no source in their svn repository for this.
So I am lost. Am I even on the right path?
I need to access this DataSource from a standalone java app (run with java -jar Myjar.jar). In fact I need to access a couple DataSources from this app.
What do I need from the server side (other than the url)?
What do I need to do on my side?