This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 3028
    
  35

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
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

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, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Facing problem running simple ejb 3.0 example using eclipse and jboss
 
Similar Threads
Need Help while running stateless session bean with Servelet bean client
problem while executing the JAR written using ANT
java don't compile my servlet.
HTTP method GET is not supported by this URL
Error to import javax.servlet.*