Using a bean class from a servlet in a Java EE application
I just started to study Java EE and made some examples (Just Hello World and some a bit more complicated). Now I'm doing a small application myself for learning purposes. I made an EAR, an EJB and an WAR just like in this example but, instead of working with interfaces, I'm working with real classes.
In summary, EJB and WAR are in the same package, but I can't instantiate an EJB class from a WAR servlet, because it doesn't seem to find that class implementation. When trying to instantiate a class called "Database" in my servlet, I got the following error from Eclipse:
Database cannot be resolved to a type
It 开发者_如何学Goalso happens with other classes.
Any idea? Thank you very much.
It sounds like you might not have the module dependencies set. The WAR project needs to have the EJB project as a module dependency.
Right click on the WAR project, click Properties, click Java EE Module Dependencies, and verify that the EJB is selected.
Module dependencies are represented in the MANIFEST.MF file of each Java EE component. That file contains the names of all the components that it depends on, and the Java EE Module Dependencies editor updates that file.
精彩评论