Reputation: 2352
Our current working Maven structure builds one EAR and is as below
workspace
>parent proj (containing root pom.xml)
>ear proj
>web proj
>jar1
>jar2
>jarN
We now need to customize this such that we build multiple EARs (for different requirements) using a combination of jars.
So the suggested workspace will now look like this:
workspace
>parent proj (containing root pom.xml)
>ear projects
>ear1
>ear2
>web projects
>web1
>web2
>component jars
>jar1
>jar2
>jarN
and in ear1 project pom.xml we want to pick and choose the web projects and jar projects which we need.
The question is:
a) is this above structure possible - since the folders named "ear projects", "web projects", "component jars" do not actually have a POM and build nothing
b) is is possible for an ear1 pom.xml to be built using artefacts outside of the same folder?
Earlier project ear1 was parallel with the jar1 and jar2 and all were child modules of the root pom.xml. But in the proposed structure, ear1 is built using the modules not in parallel, but ../web projects/web1 ../component jars/jar1 and so on.
c) is there a better way to achieve this?
Upvotes: 2
Views: 2232
Reputation: 21831
The offered workspace looks good. For clarity, I'll put it here (note, ear, web and components are all empty directories).
parent (contains root pom.xml)
|--- ear
|--- ear1 (contains ear1 pom.xml)
|--- ear2 (contains ear2 pom.xml)
|--- web
|--- web1 (contains web1 pom.xml)
|--- web2 (contains web2 pom.xml)
|--- components
|--- jar1 (contains jar1 pom.xml)
|--- jar2 (contains jar2 pom.xml)
|--- jarN (contains jarN pom.xml)
Since project dependencies are taken from repository (local or remote), there is no problem that modules aren't going to be located on the same level. You should declare them as usual dependencies. For example, in ear1 you can specify:
<dependencies>
<dependency>
<groupId>_your_groupId_</groupID>
<artifactId>_jar1_artifactId_</artifactId>
<version>_jar1_version_</version>
<dependency>
<dependency>
<groupId>_your_groupId_</groupID>
<artifactId>_web1_artifactId_</artifactId>
<version>_web1_version_</version>
<dependency>
</dependencies>
I'm not sure if I totally understand your needs, but I'll try to describe what I would do.
You can use profiles to specify which projects to build. For example, assume ear1 project depends on jar1, jar2, jar4 and web2 projects. In this case, in your root pom.xml file you can specify a profile like this:
<profiles>
<profile>
<id>ear1</id>
<modules>
<module>components/jar1</module>
<module>components/jar2</module>
<module>components/jar4</module>
<module>web/web2</module>
<module>ear/ear1</module>
</modules>
</profile>
</profiles>
If you run mvn package -P ear1
, then Maven will build only those modules that are specified in <modules>
section of the profile.
Upvotes: 3