Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem facing in Ejb execution in eclipse IDE

 
Srinivas Karthik
Greenhorn
Posts: 28
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I am new to EJB's I started with head first EJB.I am using eclipse IDE configured with JBoss 5.0.1 and I added Xdoclet for annotations purpose and configured it in eclipse. I have developed a simple bean and its two component and home interfaces and configured "ejb-jar.xml".Till this everything is fine.But after this I am not getting how to create "ejb-jar.jar" file and how to configure JNDI source etc and also how to deploy and how to see the output.PLease guide me These are the files which I have created:

Bean class(AdviceBean):
package headfirst;

import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

/**
* Session Bean implementation class AdviceBean
*/
@Stateless
public class AdviceBean implements SessionBean {

/**
*
*/

private String[] advString={"check your status","Entered correctly","Password length"};
private static final long serialVersionUID = -2874839413219948343L;

/**
* Default constructor.
*/
public AdviceBean() {
// TODO Auto-generated constructor stub
}

@Override
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
System.out.println("In activate");

}

@Override
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
System.out.println("In passivate");


}

@Override
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
System.out.println("In remove");


}

@Override
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub

System.out.println("In sessioncontext");
}

public String getAdvice()
{
int random=(int) (Math.random() *advString.length);
return(advString[random]);
}
public void ejbCreate()
{

System.out.println("In ejbCreate()");

}

}

Component interface(Advice):

/**
*
*/
package headfirst;

import java.rmi.RemoteException;

import javax.ejb.EJBObject;


public interface Advice extends EJBObject{
public String getAdvice() throws RemoteException;

}

Home interface(AdviceHome):
package headfirst;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface AdviceHome extends EJBHome{
public Advice create() throws RemoteException,CreateException;

}

ejb-jar.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<display-name>EjbSample</display-name>
<enterprise-beans>
<session>
<ejb-name>AdviceBean</ejb-name>
<home>headfirst.AdviceHome</home>
<remote>headfirst.Advice</remote>
<ejb-class>headfirst.AdviceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

Client file(AdviceClient):

import headfirst.Advice;
import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import headfirst.*;
import javax.ejb.*;

import javax.rmi.PortableRemoteObject;


public class AdviceClient {

public static void main(String k[])

{
new AdviceClient().go();
}

public void go() {
// TODO Auto-generated method stub
try
{
Context ic=new InitialContext();
Object o=ic.lookup("AdviceBean");
AdviceHome home=(AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor=home.create();
System.out.println(advisor.getAdvice());

}
catch(Exception e)
{
System.out.println("error Now in catch");
}
}
}


These are all the files after this what I have to exe4cute the EJB's please tell em step by step in detail I am after this from 2 days But in vain. Please its haunting me. please help me anyone.
Thanks in advance.

 
christian leclerc
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Srinivas,
Well ... I recommand you to use ejb3 with annotations with no descriptors.

A simple EJB looks like :



has you seam to whan some remote object, your interface should implements the remote interface from ejb ..



I recommand you to use maven2 for dependencies so that you will just have to import :




and in the client side you can do an JNDI Lookup to get the remote ejb object and it should work !

Cheers,


 
Mujahed Syed
Ranch Hand
Posts: 34
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.coderanch.com/t/572683/EJB-JEE/java/facing-Ejb-execution-eclipse-IDE

Same issue two threads!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic