Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facing problem running simple ejb 3.0 example using eclipse and jboss

 
ramakrishna kulkarni
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4587
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JBoss AS are you using? EJB 3.0 requires atleast JBoss AS 5.x.x!
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic