简体   繁体   中英

How to reuse EJB in Java EE 5+

I have a few common entity beans that I want to use in EJB module1, and EJB module2. EJB module1 may or may not be in the same EAR as EJB module2 and both EJB modules will be persist to different databases. What's the best way to reuse the common EJBs? should they be package as a JAR file or as EJB jar file?

After playing around with it a bit packaging the common EJBs in it's own EJB jar makes the most sense.

  1. Create an EJB project and add common entity beans. No persistence.xml file is need for this project

  2. Export the project as an EJB jar file.

  3. Add the jar file to the dependant EJB modules. Be sure to add the classes name in the persistence-unit of the dependant EJB modules's persistence.xml.

Hopefully this help someone with similar newbie question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM