File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Facing problem running simple ejb 3.0 example using eclipse and jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Facing problem running simple ejb 3.0 example using eclipse and jboss" Watch "Facing problem running simple ejb 3.0 example using eclipse and jboss" New topic
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

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 ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

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: 507
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facing problem running simple ejb 3.0 example using eclipse and jboss
 
Similar Threads
HTTP method GET is not supported by this URL
Need Help while running stateless session bean with Servelet bean client
java don't compile my servlet.
problem while executing the JAR written using ANT
Error to import javax.servlet.*