0
votes

I have the following project: 5(+) jars, each building specific components, with both common dependencies and jar-specific dependencies 1 war (which bundles these jars, and their dependencies) 1 ear (which holds the war and only the war)

How do I fit all of this nicely into maven?

I had the following setup:

    project-root.pom
     |- generic jar dependency 1
     |- generic jar dependency 2
     |- modules
         | - jar 1 (uses generic dependencies, and a couple of others)
         | - jar 2 (uses generic dependencies, and a couple of others)
         | - war project (uses generic jars, and jar 1 and 2)
         | - ear project

But this doesn't work, as the ear project will include the generic jar dependencies of the parent in the /lib folder.

How can such a project be set up nicely in maven?


Update

I kinda worked around it by having a root pom which declares modules for jar1, 2, the war and the ear project, but only having jar1, jar2, and the war inherit from the parent pom. The ear project doesn't. Is this proper practice?

2

2 Answers

0
votes

It should work, but you didn't reveal the contents of your project-root pom.xml. Are you using "dependencyManagement" in there, instead of just "dependencies"? It would sound to me you're not using "dependencyManagement" section, but you should, as to not get all the dependencies mentioned there to all the child modules.

0
votes

The structure you scribbled down gives me a different feeling about your project structure. Let me describe that a little bit. If i see a structure like the following i would assume:

project-root.pom
  |- generic jar dependency 1 (parent: project-root.pom)
  |- generic jar dependency 2 (parent: project-root.pom)
  |- modules
      +-- module-pom
      | - jar 1 (uses generic dependencies, and a couple of others) (parent:module-pom)
      | - jar 2 (uses generic dependencies, and a couple of others)(parent:module-pom)
      | - war project (uses generic jars, and jar 1 and 2) (parent:module-pom)
      | - ear project (parent:module-pom)

But you described in the text the relationship of the module in a differnt way:

root
 |- generic jar dependency 1
 |- generic jar dependency 2
 |- jar 1 (uses generic dependencies, and a couple of others)
 |- jar 2 (uses generic dependencies, and a couple of others)
 |- ear project
 |- war project (uses generic jars, and jar 1 and 2)

With the above structure you can simply define the dependencies in the war like depending on jar-1, jar-2. The ear depends on the war only. The jar-1 might depend on the generic-jar depency 1 and so on. The levels give the observer a different impression of the project as it really has. So you structure should represent you dependency structure. I'm not sure if this the correct structure for your project but represent the structure (folder structure) as your dependencies direct you.