Classes of referenced EJB project not found in (the referencing) Web project
I would recommend taking a look at the actual EAR that Eclipse packages and deploys to the server. You can do this by exporting the EAR project (right click on EAR project -> export -> Java EE -> EAR file)
I think the step you are missing is to add the EJB project to the WEB project's MANIFEST file. But just in case you are missing a few more steps I would check the following:
- EJB and WEB projects are modules of the EAR project. Right click the EAR project -> properties -> Deployment Assembly -> Add -> Project -> select the EJB and the WEB project. If you export your EAR project now you will notice that the EJB and the WEB project is packaged with the EAR.
- Add EJB project to MANIFEST of WEB project. Right click the WEB project -> properties -> Deployment Assembly -> Manifest entries -> Add -> select the EJB project. You can open the MANIFEST.MF file and see that it now includes the EJB project.
Also I like adding the EJB project to the WEB project build path just so that it is included in the WEB's classpath: Right click WEB project -> properties -> Java Build Path -> Projects -> Add -> Select the EJB.
ars-longa-vita-brevis
«La perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher.» Antoine de Saint-Exupery. "Every act of conscious learning requires the willingness to suffer an injury to one's self-esteem." ~ Thomas Szasz
Updated on June 04, 2022Comments
-
ars-longa-vita-brevis almost 2 years
I'm learning J2EE and EJB and I've run into a strange problem. This is my project setup:
I'm using Glassfish 3.1 and Eclipse 3.7. I have two projects in Eclipse:
- An EJB 3.0 compliant project,
myEjbProject
- A Dynamic Web Project,
myWebProject
I'm injecting an EJB session bean
mySessionBeanPackage.mySessionBean
frommyEjbProject
into a servletmyServletPackage.myServlet
inmyWebProject
and then (in the servlet) calling a simple method defined in the session bean.I've provided
myWebProject
with a reference tomyEjbProject
(using the Properties -> Project References dialog). However, for some reason, the server is unable to find the session bean. The exact error I get is:SEVERE: Class [ LmySessionBeanPackage/mySessionBean ] not found. Error while loading [ class myServletPackage.myServlet ]
Note that both the EJB project and the web project have been published to the server and I've double-checked that the class file generated for the bean is, in fact, present on the server (so I can't think of a reason why the server isn't able to find them).
Can anyone tell me what I'm doing wrong?
I've also tried
adding the classes folder of
myEjbProject
explicitly to the Java Build Path -> Libraries list ofmyWebProject
. This is in addition to the project reference (although I think adding a project reference should have sufficed in the first place). Anyway, it makes no difference (same error message as before).creating a JAR file from
myEjbProject
using the Export -> EJB Jar File option (I don't want to get into writing an Ant script at the moment). I then put this JAR in the Java Build Path -> Libraries section ofmyWebProject
. This approach does not solve the problem either (same error message as before).modifying the session bean to have
- no interface
- a local interface
- a remote interface
and modifying the injection accordingly. E.g., for a bean with only a local interface, I used:
@EJB mySessionBeanPackage.mySessionBeanLocal myBean
This approach did not solve the problem either (same error message as before).
doing away with
myEjbProject
altogether and adding the session bean tomyWebProject
asmyServletPackage.mySessionBean
(same package as the servlet). In this case, I can inject the session bean successfully into the servlet using@EJB mySessionBeanPackage.mySessionBean myBean
doing away with
myEjbProject
altogether and adding the session bean tomyWebProject
asmySessionBeanPackage.mySessionBean
(a new package). In this case also, I can inject the session bean successfully into the servlet using@EJB mySessionBeanPackage.mySessionBean myBean
- An EJB 3.0 compliant project,
-
ars-longa-vita-brevis over 12 yearsNo. 2 did the trick for me. Thank you, thank you, thank you! :) I haven't created an EAR project as yet because I thought I'd start out simple. And the last line, yes, I had that already. Cheers.
-
Admin almost 12 yearsExcellent! #2 saved me more hair pulling. Thanks!