Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Calling ejb from jsp

  Asked By: Richard    Date: Sep 30    Category: Java    Views: 822

I m tring to create a session ejb which prints some text in both server aswellas
client side.
I have just compiled following .java file in to following directory and created
ejb-jar.xml file
in the same.I have created a jar file named 'HelloWorld.jarContent' in the same
This is where ur help is requested, I dont know
1. How the created ejb is invoked from client(Please get me exact coding)
2. Is any changes in ejb-jar.xml needed
3. Where these files r stored(directory structure)
4. How could I run the program for testing
Tools I m using
Netbeans 3.6

working directory
Present contents
1. Hello.class
2. HelloBean.class
3. HelloClient.class
4. HelloHome.class
5. HelloLocal.class
6. HelloLocalHome.class
7. ejb-jar.xml
8. HelloWorld.jarContent
My file contents
1. Hello.java
package examples;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface Hello extends javax.ejb.EJBObject
public String hello() throws java.rmi.RemoteException;
2. HelloBean.java
package examples;
import javax.ejb.*;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;

public void ejbCreate()

public void ejbRemove()
public void ejbActivate()
public void ejbPassivate()
public void setSessionContext(javax.ejb.SessionContext ctx)
this.ctx = ctx;
public String hello()
return "Hello World";
3. HelloClient.java
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient
public static void main(String[] args) throws Exception
{ Properties props = System.getProperties();
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj,
Hello hello = home.create();
4. HelloHome.java
package examples;
public interface HelloHome extends javax.ejb.EJBHome
Hello create() throws java.rmi.RemoteException,javax.ejb.CreateException;
5. HelloLocal.java
package examples;
public interface HelloLocal extends javax.ejb.EJBLocalObject
public String hello();
6. HelloLocalHome.java
package examples;
public interface HelloLocalHome extends javax.ejb.EJBLocalHome
HelloLocal create() throws javax.ejb.CreateException;
7. ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
Document : web.xml
Created on : July 4, 2004, 7:13 AM
Author : Administrator
Purpose of the document follows.
8. HelloWorld.jarContent



1 Answer Found

Answer #1    Answered By: Maliha Malik     Answered On: Sep 30

First of all, which application server  are you using, coz all these servers have
different ways/tools for creation of deployment jar.

Didn't find what you were looking for? Find more on Calling ejb from jsp Or get search suggestion and latest updates.