wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Help to solve NoInitialContextException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Help to solve NoInitialContextException" Watch "Help to solve NoInitialContextException" New topic
Author

Help to solve NoInitialContextException

anoop estuate
Greenhorn

Joined: Mar 12, 2009
Posts: 4
Hi friends
I have devloped a ejb program in netbeans, the details of the program are listed below...
//*******************************************************************************
This is my ejb-jar.xml file
//********************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>EJBModule1</display-name>
<enterprise-beans>
<session>
<display-name>AdviceBeanSB</display-name>
<ejb-name>AdviceBeanBean</ejb-name>
<home>com.headfirst.AdviceBeanRemoteHome</home>
<remote>com.headfirst.AdviceBeanRemote</remote>
<ejb-class>com.headfirst.AdviceBeanBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>AdviceBeanBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
//*************************************************************************************************
This is my sun-ejb-jar.xml
//**************************************************************************************************

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>AdviceBeanBean</ejb-name>
<jndi-name>Advisor</jndi-name>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
//*************************************************************************************************
This is my client program(Stand alone program)
//*************************************************************************************************

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.client;

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.headfirst.*;
import javax.ejb.*;
import java.util.*;
import java.io.*;



/**
*
* @author ESTUATE
*/
public class AdviceClient
{
public static void main(String arg[])
{
try
{
Context ic = new InitialContext();
Object o = ic.lookup("Advisor");
AdviceBeanRemoteHome home = (AdviceBeanRemoteHome)PortableRemoteObject.narrow(o, AdviceBeanRemoteHome.class);
AdviceBeanRemote advisor = home.create();
System.out.println(advisor.getAdvice());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
//**************************************************************************************
The problem i am facing is when ever I am running the program I am getting the following error
//*************************************************************************************
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\ESTUATE\My Documents\NetBeansProjects\EJBModule1\build\jar
compile-single:
run-main:
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:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.client.AdviceClient.main(AdviceClient.java:30)
BUILD SUCCESSFUL (total time: 1 second)


Can any one help to solve this problem....Thanks in advance

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

See Reza's answer here http://www.coderanch.com/t/435153/EJB-Other-Java-EE-Technologies/java/Initial-Context-Exception#1933895


[My Blog] [JavaRanch Journal]
anoop estuate
Greenhorn

Joined: Mar 12, 2009
Posts: 4
Hi,
I have given all the details about the program. The jndi name in sun-ejb jar.xml file should match with the
//***********************************************************
sun-ejb jar.xml
//***********************************************************
<ejb>
<ejb-name>AdviceBeanBean</ejb-name>
<jndi-name>Advisor</jndi-name>
</ejb>

and
//**************************************************************
The client program
//**************************************************************

Object o = ic.lookup("Advisor");

//***************************************************************
Still why it is showing the error
//***************************************************************
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:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.client.AdviceClient.main(AdviceClient.java:29)


CAN ANY ONE HELP ME TO SOLVE THIS PROBLEM PLEASE!!!
Thanks in advance.....
 
wood burning stoves
 
subject: Help to solve NoInitialContextException
 
Similar Threads
EJB transaction
Initial Context Exception
Problem deploying ejbs in weblogic
Context Lookup Failing
Setting transaction attributes