Wednesday, January 2, 2013

Multiple Modules EJB, JPA, JAR, WAR - Maven Netbeans

I hope this can be a useful post for those who are looking to do an EAR project, with multiple modules.
First stop, using Netbeans 7.2.1 create Maven Enterprise Application, and this will give you the EAR, EJB, and WAR project. You will have one parent project which consists only one pom.xml
  1. Create a new module, a JAR project, to contain all your POJO classes, supposedly your entity classes, java classes with @Entity annotation. Nothing else, only POJO classes. Note: don't forget to include these classes in your persistence.xml file, this is where you put the persistence.xml, not anywhere else.
  2. In your EJB projects, placed all your session beans, in NetBeans, normally this has suffix "Facade". This is where the EntityManager lives. Note: don't forget to include your database dependency jar, for MySQL is something like mysql-connector-java, there is one for PostgreSQL as well. Include JAR project as dependency here.
  3. In your WAR projects, all web application files, html, css, images, resources and etc. This is where your controller files (managed beans, converters, utils, and etc) live. Note: include JAR, and EJB projects as dependencies here.
  4. Finally, your EAR projects, which is supposed to package all three modules above.
    • Your glassfish-resources.xml should be here (if you want to use application scoped resources).
    • In your EAR pom.xml, package the JAR project into a folder called "lib" or whatever name you specify in the <defaultLibBundledir/>.
    • Use option <unpack>true</unpack>.
    • List all three modules above as dependency
  5. You should be good to go

No comments: