-
1. Re: JNDI with no jndi.properties
prasad.deshpande Jul 8, 2011 5:43 AM (in response to iapazmino)1 of 1 people found this helpfulIt's probably that you have jndi.properties in your application classplath & because of which you are getting this exception. Please try to remove it & then try again to build your Context. Context ctx = new InitialContext();
-
2. Re: JNDI with no jndi.properties
gerry.matte Jul 8, 2011 2:06 PM (in response to iapazmino)1 of 1 people found this helpfulI found that a simple way to quickly make your programs work is to comment out all the lines in your jndi.properties file.
That allows your legacy code to be unchanged and it seems to prevent the NamingException.
Alternatively, you can change the code
InitialContext ctx = new InitialContext(jndiproperties);
to instead beInitialContext ctx = new InitialContext( );
-
3. Re: JNDI with no jndi.properties
iapazmino Jul 8, 2011 3:22 PM (in response to gerry.matte)Thank you for your replies. I think I shouldn't have omitted a big detail, I'm trying to get a reference to an EJB2 component deployed in a different server from where I'm trying to consume, so I need to specify the java.naming.provider.url's ip address somewhere and I don't think you can do this using
@EJB(lookup="jndi/properties/including/ip/address")
-
4. Re: JNDI with no jndi.properties
gerry.matte Jul 8, 2011 3:23 PM (in response to gerry.matte)If you want some tested code from one of my servlets:
DataSource ds; Connection con; try { InitialContext ctx = new InitialContext(); Context datasourcesCtx = (Context) ctx.lookup("java:jboss/datasources"); ds = (DataSource) datasourcesCtx.lookup("ExampleDS"); out.println("<p>Success: looked up ExampleDS and cast the resulting Object as a DataSource</p>"); con = ds.getConnection(); out.println("<p>Success: obtained a JDBC connection from ExampleDS</p>"); con.close(); } catch (NamingException nex) {System.err.println(nex);out.println("NamingException:<BR>"+nex+"<BR>");} catch (SQLException e) {System.err.println(e);out.println("SQLException:<BR>"+e+"<BR>");} finally {}; -
5. Re: JNDI with no jndi.properties
iapazmino Jul 8, 2011 3:40 PM (in response to gerry.matte)Thank you. Still, this datasource is installed in the same instance, or same server at least, where your container is deployed. But I need to access a component in a different IP address in a different server. An as4.3 server actually, and, my container is deployed to an as7 in localhost. So, I believe I need to set the java.naming.provider.url somewhere so the service may be found.
-
6. Re: JNDI with no jndi.properties
prasad.deshpande Jul 8, 2011 3:55 PM (in response to iapazmino)Yes, I guess error you are getting is about
org.jnp.interfaces.NamingContextFactory
being not found is due to the fact that in earlier releases, it used to packaged with client jar, for AS7 it's not yet available in CR1/Final release. But I guess even though I haven't tried, you can still setjava.naming.provider.url=<host_name>:<port> property in hashtable & pass it to the contructor of InitialContext & that should ideally work.
-
7. Re: JNDI with no jndi.properties
iapazmino Jul 8, 2011 4:28 PM (in response to prasad.deshpande)Thank you, it did work.
What I actually did was just deleting these two entrances from the properties file
java.naming.factory.initial
java.naming.factory.url.pkgs
So I still have the jndi.properties in my app's classpath holding the provider url and a dependency to the jnp client