Generic ejb 3 for multiple glass wool web projects

I currently have a J2EE project containing EJB and WAR. Everything is going well, as long as I have only one WAR and one EJB module included in the final EAR. Now I need to develop another WAR using the same EJB module.

So, I added the EJB module to the library of the new WAR. The problem is that when I try to deploy an EAR bundled with two WARs and a shared EJB, I get the following exception:

Caused by: java.lang.RuntimeException: Error while binding JNDI name com.alex.ejb.MyBeanRemote__3_x_Internal_RemoteBusinessHome__ for EJB : MyBean

When I remove the EJB from the library of the second WAR, everything works again.

Is there something I missed?

Finally, the real question is: "How to share EJB in multiple web applications?"

thanks for the help

+3
source share
2 answers

The problem is that when I try to deploy an EAR complete with two WARs and a shared EJB, I get the following exception (...)

This is because beans is deployed twice, causing a name clash. In fact, this is simply not how you should package your application when using EAR packaging.

Finally, the real question is: "How to share EJB in multiple web applications?"

Do not put EJB modules in the folder of WEB-INF/libyour web modules, your EAR should have the following structure:

myear.ear
| - META-INF
| | - application.xml
| `- sun-application.xml (optional)
| - myejbmodule1-ejb.jar
| - ...
| - myejbmoduleN-ejb.jar
| - mywebapp1-war.war
`- mywebapp2-war.war

Resources

+3

EJB WAR, JNDI . JAR, (), , .

0

Source: https://habr.com/ru/post/1772086/


All Articles