Simpel EJB session client - problemer med JNDI lookup
Simpel EJB session client - problemer med JNDI lookupJeg prøver at få en simpel EJB session client til at virke (jeg eksikvere den fra Oracle9i Jdeveloper) men jeg får følgende 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: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 examples.HelloClient.main(HelloClient.java:36)
jeg benytter j2sdk1.4.2_04
Please hjælp:
Her er kode:
--------------------------------------
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
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.PortableRemoteObject.narrow(
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.hello());
/* 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("ejbCreate()");
}
public void ejbRemove()
{
System.out.println("ejbRemove()");
}
public void ejbActivate()
{
System.out.println("ejbActivate()");
}
public void ejbPassivate()
{
System.out.println("ejbPassivate()");
}
public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()");
}
// 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;
}
Hvis der er nogen der kan lave et et simpelt eks. på hvordan man invoker en EJB entity object fra en EBJ session bean ville det være super cool :-)