Maven multi project - maven

I have a several maven module (3 jar and 2 war, modules are interconnected).
My purpose is combine this modules to one ear file.
Example: in ear maven project I run in lifecycle "package" goal, when all maven project, who include in global project are execute "package" goal and when creating global ear, who include jar (war) from other maven project.
How do this?
I create global project as <packaging>pom</packaging>, it execute "package" goal from dependency project
<modules>
<module>...</module>
</modules>
but how create ear?

You should use <packaging>ear</packaging> instead of pom.
It will force maven to use maven-ear-plugin on package phase (so you don't need to provide any executions of this plugin).
You could find simple example here: Maven EAR Plugin Example

Related

Maven goal to move file to another directory

I need to move the war generated to some other directory with maven goal.
I know how to move it to another location by adding configuration in pom.xml but i need to do it with a goal.
Which i can run directly without using pom.xml
like: mvn jboss-as:deploy-only deploys jboss with war generated without including any plugin specific configuration in POM.
Their are some restrictions to plugins which can be used in pom. So need to use Maven Goal only

In maven multimodule project is it recommended to use package or install

I have a maven multimodule project
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
</modules>
Module C depends on Module A. In this project structure can you let me know it is recommended to use package or install. I do not have any other requirement to share this project with other projects.
When launching a Maven command on multiple modules, if a dependency specified in one module is available as a project being built in the same command, Maven will use the output of the current build as dependency, instead of the JAR present in the local repository.
So it is not necessary to use install to make the changes of a module available to modules depending on it, as long as these modules are always built together.

Create a maven project with parent's packaging war

I want to create a Maven project. I want it to have a parent project. The problem is that the parent project has a package in: war.
I see an error :
Invalid packaging for parent POM must be "pom" but is "war"
What should I do ?
A parent project (packaging with type pom) is by definition a container of submodules. Only the submodules are allowed to be of specific packaging types (like war or jar). You use a parent project to aggregate common dependencies and build configurations.
I suggest that you put the code you want to reuse in a submodule of type jar and then add this submodule as a dependency of other projects you have (with packaing type war or jar).
You could read Chapter 6 of the book Maven by Example where it illustrates how to build a maven multi-module project.

how to run only specific maven module

how to run only specific maven module from maven eclipse project.
I have few modules in my EAR maven project and when I build whole project it fails at one module WAR,saying this war artifact module not found in repository.
Your multi module project must e having a common parent. First install that parent pom in your local repository. Now go to child module project and maven build the project.
It should work given that all its dependencies are present.

Maven packaging ear finding dependency from project level but not from parent

I've currently got a parent pom that declares two modules: an ear and a war. The ear is reliant on the war (and declares a dependency for it with group/artifact id and packaging type).
When packaging from the parent pom level, the reactor picks up both artifacts and properly packages the war into the ear as you would expect. However, when packaging from the ear's project pom (despite having declared elements in both projects pointing to the parent pom) the ear fails to find the war artifact.
I know that when packaging at the ear level Maven finds its way to the parent correctly, but does it not then iterate down to the various modules that the parent contains to pick up artifacts?
Thanks :)
That's the way Maven works. It's OK. When resolving dependencies, Maven looks for them in reactor, then local repository, then remote repos. So, when doing a build from a parent project level, both projects are in the reactor, so EAR can pick WAR easily. (To be specific, it's not because the parent-child relation, but the fact they are modules.) However, when you build an EAR module in isolation, reactor can't provide WAR as well as local repo as well as remote repos. If you install WAR module into local repo by mvn install and then try to build EAR, WAR artifact will be found using local repo.
Sounds like your parenting structure is broken, if the EAR depends on the WAR then it should be a child module.

Resources