Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem facing in Ejb execution in eclipse IDE

 
Greenhorn
Posts: 28
Eclipse IDE Oracle Java
  • 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.

 
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,


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

Same issue two threads!
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic