• Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.naming.NoInitialContextException ?  RSS feed

 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naming properties are need to be set to the context.

context = new InitialContext(properties);


 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure java version of the client program is same as ejb deployed server java version.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!