• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i use EJB in servlets

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have created a EJB project using eclipse successfully deployed into weblogic server
Now i have created Another webApp using eclipse in that i have created Servlet. How can use this EJB in Servlet.



but i am getting Caused By: java.lang.ClassNotFoundException: info.fcs.MyTestEJBLocal
any help

Thanks
Rajendar
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the EJB project added as a dependency to your servlets project? The last time I used EJB's were in 2009 and I remember very vaguely that you have to provide a descriptor file that would tell which EJB to inject. I'm not sure how things changed since then.
 
raj talatam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Harry wrote:Is the EJB project added as a dependency to your servlets project? The last time I used EJB's were in 2009 and I remember very vaguely that you have to provide a descriptor file that would tell which EJB to inject. I'm not sure how things changed since then.



Thanks after adding that error got resolved and end up with

 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd advice you to pick up an EJB 3 book and go through the steps of creating and deploying EJB's to Java EE containers.
 
Author
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
easiest thing to do is to create a 3rd project, which is Maven EAR project. Have dependencies on both the EJB and the Servlet project so they both get packaged in the EAR. Then deploy the EAR as a single unit to weblogic. From your servlet, you can either use either @EJB MyTestEJBLocal MmyTestEJBLocal; or @Inject MyTestEJBLocal myTestEJBLocal;
 
Ranch Hand
Posts: 99
MyEclipse IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Had the same problem just recently. It's a Weblogic specific problem.

1. If your web app is a part of an EAR and your session bean is there as well just make sure the webapp has the ejb module in its dependency and EAR's application.xml has the ejb module listed. All annotations should work just fine.

2. If you try to access a remote interface of a session bean from another application:

Solution 1: Use a custom service locator looking by the remote facade's global JNDI name (java:global/earname/ejbmodulename/MyFacade!com.package.MyFacadeRemote)

Solution 2: Declare your session bean with mappedName parameter (@Stateless(name = "MyFacade", mappedName = "MyFacade")) making it appear in the root of the JNDI context. And then initialize the remote facade using the same mappedName (@EJB(mappedName = "MyFacade"))


Hope it helps
 
pie. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic