Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsI trying to make a simple EJB session client work (I'm running the client from within Oracle9i Jdeveloper) but I get the following error:
javax.naming.NoInitialCont
at javax.naming.spi.NamingMan
at javax.naming.InitialContex
at javax.naming.InitialContex
at javax.naming.InitialContex
at examples.HelloClient.main(
Please help
Here is the code:
package examples;
import javax.naming.Context;
import javax.naming.InitialContex
import java.util.Properties;
/** This class is an example of client code which invokes
* methods on a simple stateless session bean. */
public class HelloClient {
public static void main(String[] args) throws Exception {
/* Setup properties for JNDI initialization.
* These properties will be read-in from
* the command-line. */
Properties props = System.getProperties();
/* Obtain the JNDI initial context.
* The initial context is a starting point for
* connecting to a JNDI tree. We choose our JNDI
* driver, the network location of the server, etc
* by passing in the environment properties. */
Context ctx = new InitialContext(props);
/* Get a reference to the home object - the
* factory for Hello EJB Objects */
Object obj = ctx.lookup("HelloHome");
/* Home objects are RMI-IIOP objects, and so
* they must be cast into RMI-IIOP objects
* using a special RMI-IIOP cast. */
HelloHome home = (HelloHome)
javax.rmi.PortableRemoteOb
obj, HelloHome.class);
/* Use the factory to create the Hello EJB Object */
Hello hello = home.create();
/* Call the hello() method on the EJB object. The
* EJB object will delegate the call to the bean,
* receive the result, and return it to us.
*
* Print the result to the screen. */
System.out.println(hello.h
/* Done with EJB Object, so remove it.
* The container will destroy the EJB object. */
hello.remove();
}
}
package examples;
import javax.ejb.SessionContext;
/**
* Stateless session bean */
public class HelloBean implements javax.ejb.SessionBean
{
// EJB-required methods
public void ejbCreate()
{
System.out.println("ejbCre
}
public void ejbRemove()
{
System.out.println("ejbRem
}
public void ejbActivate()
{
System.out.println("ejbAct
}
public void ejbPassivate()
{
System.out.println("ejbPas
}
public void setSessionContext(SessionC
{
System.out.println("setSes
}
// Business methods
public String hello()
{
System.out.println("hello(
return "Hello, World!";
}
}
package examples;
/** This is the HelloBean remote interface. */
public interface Hello extends javax.ejb.EJBObject
{
/* The one method - hello - returns a greeting to the client. */
public String hello() throws java.rmi.RemoteException;
}
package examples;
/**This is the home interface for HelloBean.*/
public interface HelloHome extends javax.ejb.EJBHome
{
/** This method creates the EJB Object.
* @return The newly created EJB Object. */
Hello create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
package examples;
/**This is the HelloBean local interface.*/
public interface HelloLocal extends javax.ejb.EJBLocalObject
{
/** The one method - hello - returns a greeting to the client. */
public String hello();
}
package examples;
public interface HelloLocalHome extends javax.ejb.EJBLocalHome
{
/**This method creates the EJB Object.
* @return The newly created EJB Object. */
HelloLocal create() throws javax.ejb.CreateException;
}
I also need somone to make a simple example of how to invoke a EJB entity object from with the session bean
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: mhci_nnePosted on 2007-03-24 at 06:04:40ID: 18785031
Comments are available to members only. Sign up or Log in to view these comments.