| Author |
Facing problem running simple ejb 3.0 example using eclipse and jboss
|
ramakrishna kulkarni
Greenhorn
Joined: Feb 06, 2009
Posts: 14
|
|
Hi All
I am learning ejb 3.0 now, and started hands on with this example
This is the local interface
package com.web;
import javax.ejb.Local;
@Local
public interface GreetUserLocal {
public String sayHello();
}
The implementation class is like this
package com.web;
import javax.ejb.Stateless;
/**
* Session Bean implementation class GreetUser
*/
@Stateless
public class GreetUser implements GreetUserLocal {
/**
* Default constructor.
*/
public GreetUser() {
// TODO Auto-generated constructor stub
}
@Override
public String sayHello() {
// TODO Auto-generated method stub
return "Hello World";
}
}
The servlet client is like this
public class InvokeEJB extends HttpServlet {
public InvokeEJB() {
super();
}
@EJB
private GreetUserLocal greet;
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
String greetings = greet.sayHello();
out.println(greetings);
}
}
============================
I am getting an error like this
java.lang.NoClassDefFoundError: com/web/GreetUserLocal
com.web.InvokeEJB.doPost(InvokeEJB.java:52)
Please let me know where am going wrong
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2701
|
|
Please UseCodeTags when you post a code. It's unnecessarily hard to read the code otherwise.
Please edit your post to add code tags by clicking the button.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
|
Which version of JBoss AS are you using? EJB 3.0 requires atleast JBoss AS 5.x.x!
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
|
|
Hello,
It may be helpful if you tell how you are deploying the application.
Based on the error I think that the packaging might be the issue.
Regards,
Amit
|
 |
Tony Tung
Greenhorn
Joined: Aug 07, 2009
Posts: 17
|
|
I double DI like @EJB can be used in client side .
Maybe you could use JNDI - lookup method to invoke session bean class .
|
 |
Tony Tung
Greenhorn
Joined: Aug 07, 2009
Posts: 17
|
|
Tony Tung wrote:I double DI like @EJB can be used in client side .
Maybe you could use JNDI - lookup method to invoke session bean class .
I correct my word , @EJB can use in client side .
but should annotate like @EJB GreetUserLocal guser
and invoke bean class method guser.sayHallo()
|
 |
Rajasekhar Devi Reddy
Greenhorn
Joined: Dec 21, 2007
Posts: 29
|
|
|
Depending on your JBOSS version DI in servelets might not work. At least in my case DI in servlets did not work for JBOSS version 4.2.3 so I changed my code to do a JNDI look up.
|
 |
 |
|
|
subject: Facing problem running simple ejb 3.0 example using eclipse and jboss
|
|
|