aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes javax.naming.NoInitialContextException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "javax.naming.NoInitialContextException ?" Watch "javax.naming.NoInitialContextException ?" New topic
Author

javax.naming.NoInitialContextException ?

Mishaal Khan
Ranch Hand

Joined: Aug 21, 2008
Posts: 61
I am new to EJB3 and trying to run an application based on tutorial

http://www.laliluna.de/download/first-ejb3-tutorial-en.pdf

1) The JNDI name is defined in a file bookstore-ds.xml which is in ....jboss/server/deploy directory

2) The JNDI name is being referenced like :

public static final String RemoteJNDIName = BookTestBean.class.getSimpleName() + "/remote";

3) When I try to run the Client program as below:

Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.namingrg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");

Context context;
try
{
context = new InitialContext();
BookTestBeanRemote beanRemote = (BookTestBeanRemote) context.lookup(BookTestBean.RemoteJNDIName);
beanRemote.test();
} catch (NamingException e)
{
e.printStackTrace();
/* I rethrow it as runtimeexception as there is really no need to continue if an exception happens and I
* do not want to catch it everywhere.
*/
throw new RuntimeException(e);
}

I get following exception :

javax.naming.NoInitialContextException:Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)

When I look into Namespace view using JNDIView service ,it seems like JNDI name is not bound
Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
+- bookDatasource (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+- TransactionPropagationContextExporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
+- Mail (class: javax.mail.Session)
+- comp.ejb3 (class: javax.naming.Context)
| NonContext: null
+- TransactionPropagationContextImporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- TransactionManager (class: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate)


Any suggestions ?

Thanks.



Uppala Ramana
Greenhorn

Joined: Jan 14, 2010
Posts: 14
Naming properties are need to be set to the context.

context = new InitialContext(properties);



Ramana Uppala
SCJA,SCJP
Mishaal Khan
Ranch Hand

Joined: Aug 21, 2008
Posts: 61
Thank you very much , I tried declaring the seperate jndi.properties file and it worked but good to know
this option also , thanks again.

Now I have another problem as I proceed ,When I try to run the Client program ,which is
calling a bean method which is using an entity bean , I am getting following error:

java.io.InvalidClassException: org.jboss.ejb3.LocalProxy; local class incompatible: stream classdesc serialVersionUID = 6042646703631784907, local class serialVersionUID = -6521545933800264895

I found one of the reason on a website that if jbossall-client.jar is added later on and jboss version is different
this problem happens ,but in my case this file belongs to same version of jboss.What could be the other reason?
I set my serialVersionUID = 1L

Thanks.

Uppala Ramana
Greenhorn

Joined: Jan 14, 2010
Posts: 14
Make sure java version of the client program is same as ejb deployed server java version.

 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: javax.naming.NoInitialContextException ?
 
Similar Threads
Pass security context to JBoss
Can't run first Session Bean : NameNotFoundException
EJB 3 javax.naming.Communication Exception
Exception in thread "main" javax.naming.NoInitialContextException:
EJB 3 javax.naming.Communication Exception