2

How do you organize your Maven modules in a Java EE application? Currently what we do is have the following Maven modules under a parent POM:

  • ear
  • ejb
  • ejb-api
  • core

The ejb module contains only EJB classes, while the core module contains all other utility classes, including entities. The ejb-api is a lightweight module that contains local and remote interfaces, for inclusion in separate applications in needed. ear is used to make an EAR package and deploy it to application server.

How do you structure your application? I am particularly interested in where you store your utility classes and entity classes.

Ariod
  • 5,757
  • 22
  • 73
  • 103
  • 1
    I liked the default netbeans directory structure `myapp-ejb, myapp-war etc` but not too keen on netbeans itself so pretty much coppied this and used ant with ivy which I personally found quicker to get to grips with then Maven. I have tried to keep utility classes etc reusable and uncoupled from my modest jee project and have those in a seperate 'library type' project which is included as you would with any library. I also package by name (or whatever this is called) where for example if I am working on entities for a company structure type model they would be packaged in `foo.company` – T I Jan 13 '12 at 11:58
  • JEE apps often being web apps, it's common to have a `myapp-war` project containing the webapp-specific code. Might not apply to you. We don't separate ejb and ejb-api into their own modules; but it's a sensible idea and we probably should. – Andrew Spencer Jan 13 '12 at 13:28
  • 1
    @Dario: You should organize your project with principle "1 module = 1 deliverable". Deliverable is WAR, EAR, JAR, ... – dma_k Jan 14 '12 at 18:29

2 Answers2

3

Maven has the concept of archetypes that layout a pre-defined structure. I recommend the predefined archetypes from org.codehaus.mojo.archetypes. They have archetypes from desktop applications to server side applications (j2ee 1.3 to Java EE 6).

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
1

IDE's like Websphere RAD, Oracle JDeveloper usually create different projects for each.

With maven, you can just use one module and extract common code, interfaces into the client jar using maven-ejb-plugin, ok keep them separate. Only thing is project should use one and follow a consistent approach

hth

<plugin>
  <artifactId>maven-ejb-plugin</artifactId>
  <configuration>
  <ejbVersion>3.0</ejbVersion>
  <generateClient>true</generateClient>
  <clientIncludes>
    <clientInclude>com/foo/goo/**/model/**</clientInclude>
   <clientInclude>com/foo/goo/**/service/**</clientInclude>
  </clientIncludes>
 </configuration>
</plugin>
user1132593
  • 448
  • 1
  • 5
  • 8