Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

WSAD 5.1.0 EJB Application Testing Problem  RSS feed

 
Naveen Kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am getting below Exception:

javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:101)
at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:74)
at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:591)
at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:540)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:287)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at HelloWorld.lookupService(HelloWorld.java:23)
at HelloWorld.main(HelloWorld.java:34)

My Sample Code is:

public class HelloWorld
{
private Object lookupService(String referenceName)
{
try
{
Context aContext = new InitialContext();
return aContext.lookup("java:comp/env/" + referenceName);
}
catch (NamingException e)
{
e.printStackTrace();
}
return null;
}
public static void main(String[] args)
{
HelloWorld d = new HelloWorld();
d.lookupService("ejb/Example");
}
}
 
Anurag Gupta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a similar issue.
It looks like, the java:comp/xxx is available only from within the container.
From outside the container (in a stand alone java client), you would need to look up the exact JNDI Name.

Going a step further :
InFact, a pojo which is deployed on the appserver along with some EJBs (as a dependent jar file) is also unable to use java:comp/xxx to look up any resource.
Bottom Line: Only EJBS and Servlets can use java:comp/xxx.

Anyone has a better idea/alternative ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!