Hello all,
i have
ejb program consists of following files:
in Hello directory
HelloHome
package Hello;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
public interface HelloHome extends javax.ejb.EJBHome
{
Hello.HelloInterFace create() throws
java.rmi.RemoteException,
javax.ejb.CreateException;
}
Hello Bean
package Hello;
import javax.ejb.SessionContext;
public class HelloBean implements javax.ejb.SessionBean
{
private SessionContext ctx;
public void ejbCreate() {
System.out.println("You are inside ejbCreate()");
}
public void ejbRemove() {
System.out.println("You are inside ejbRemove()");
}
public void ejbActivate() {
System.out.println("You are inside ejbActivate()");
}
public void ejbPassivate() {
System.out.println("You are inside ejbPassivate()");
}
public void setSessionContext(javax.ejb.SessionContext ctx) {
this.ctx = ctx;
}
public
String hello()
{
return "Hello to everyone and welcome to the Interview question series";
}
}
HelloInterface
package Hello;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface HelloInterFace extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}
HelloClient
package Hello;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient {
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming
rg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context ctx = new InitialContext(properties);
System.out.println("Got context");
Object obj = ctx.lookup("hello/Hello");
System.out.println("Got reference");
HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
HelloInterFace hello = home.create();
System.out.println("Created Home object");
System.out.println(hello.hello());
System.out.println("Called the actual method");
hello.remove();
System.out.println("Removed the object from the container");
}
}
And these files are there in WEB-INF/classes/Home
And Deployment ddescriptors like
ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<display-name>Hello</display-name>
<enterprise-beans>
<session>
<display-name>Hello</display-name>
<ejb-name>Hello</ejb-name>
<home>Hello.HelloHome</home>
<remote>Hello.HelloInterFace</remote>
<ejb-class>Hello.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
weblogic-ejb-jar.xml consists of
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<!-- Sample MessageDriven bean Weblogic deployment descriptor -->
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Hello</ejb-name>
<jndi-name>hello/Hello</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
These xml files are there in META-INF directory
please tell me how to deploy and execute this application.