Hi,
This is my complete program interfaces bean class and a main method client
HelloBean.java -The bean implementation class
package advice;
import javax.ejb.*;
public class HelloBean implements SessionBean, HelloLocalBusiness {
private SessionContext context;
public void setSessionContext(SessionContext aContext) {
context = aContext;
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbRemove() {
}
public void ejbCreate() {
// TODO implement ejbCreate if necessary, acquire resources
// This method has access to the JNDI context so resource aquisition
// spanning all methods can be performed here such as home interfaces
// and data sources.
}
public
String sayHello() {
return("Hello");
}
}
HelloLocal.java-Component interface
package advice;
import javax.ejb.EJBLocalObject;
/**
* This is the local interface for Hello enterprise bean.
*/
public interface HelloLocal extends EJBLocalObject, HelloLocalBusiness {
}
HelloLocalHome.java
package advice;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
/**
* This is the local-home interface for Hello enterprise bean.
*/
public interface HelloLocalHome extends EJBLocalHome
{
HelloLocal create() throws CreateException;
}
HelloLocalBusiness.java
package advice;
/**
* This is the business interface for Hello enterprise bean.
*/
public interface HelloLocalBusiness {
String sayHello();
}
HelloClient.java
package client;
import advice.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import javax.ejb.*;
import java.util.*;
public class HelloClient {
/** Creates a new instance of HelloClient */
public HelloClient() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try
{
Properties prop=System.getProperties();
prop.put("INITIAL_CONTEXT_FACTORY","java.naming.factory.initial");
Context ctx=new InitialContext(prop);
Object o=ctx.lookup("ejb.Hello");
HelloLocalHome helloHome=(HelloLocalHome)o;
HelloLocal hello=helloHome.create();
System.out.println(hello.sayHello());
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
output for this client program is follows
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:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at client.HelloClient.main(HelloClient.java:37)
I have compiled this program numerous times but got the same result.I used netbeans5.0
IDE and Sun
Java Apps Server 8.2. Help me to give the detailed code with descriptions of settings for env entries and URL Specifications to access the local host.
Thanks and regards,
Ramesh RK