How to create ear using using another project war through multi module approach - maven

I have one maven project(lets say Proj1) which creates a war file. I want to create a parent project(lets day Proj2) which will create an .ear using the war project. So that when I build Proj2, it should build the war from Proj1 and then use it to create .ear

What you need is your project to be structured this way:
Parent project (packaged as pom)
-->Child-EAR project (packaged as EAR)
-->Child-WAR project (packaged as WAR)
Each project should have a pom file, parent project should include the child projects as its module. The child project should include the parent module. Please see this link: https://www.javacodegeeks.com/2014/04/java-ee7-and-maven-project-for-newbies-part-1-a-simple-maven-project-structure-the-parent-pom.html it explains in detail.

Related

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.

Build child jar using parent war using maven

I need to create a dependent maven project.
The child one should be a jar, that would be called by the parent project which should be a war file.
The steps should be like this. When I build the war, it should automatically build the jar file and include it and build the war and show output of the child jar (suppose a simple print statement).
Note: Build should be done only once and that is for building the final war.
Need to edit the pom.xml accordingly.
I am new to maven,so a bit elaborate solution would be very helpful.

maven - need to create ear bundle

I have a maven project which currently creates a war package on build. Now I need to bundle it as an ear project. Any pointers on how to do this. I added the m2e plugin and modified the pom.xml file, but, i am not able to get the directory structure as expected. I need the dir structure as below
project-name
- project-name.ear
- pom.xml
- project-name.war
- projec-name.jar
- META-INF/application.xml
Thanks.
It is strongly recommend that you organize your project structure in proper Maven style:
project-name/
- pom.xml (POM of project-name, multi-module POM)
+ project-name-jar
- pom.xml (main app JAR)
+ project-name-web
- pom.xml (WAR project to construct WAR by project-name-jar etc)
+ project-name-ear
- pom.xml (EAR project to construct EAR by project-name-war etc)
Normally I will have another child project call project-name-parent which use as parent POM for the whole project.
In Maven, you don't and you shouldn't have META-INF/application.xml as part of your source. It is generated dynamically base on configuration of maven-ear-plugin.

Building all dependencies in Maven

I have a Ear, war and 2 jar projects in my eclipse.
I want to automatically build 2 jars, war and ear project, when i run the pom inside ear project.
I remember doing this in maven in the past. But i forgot since i lost touch working with Maven for few years now.
Someone please remind me of that..
I used dependency compile, but it is not building jar, when i build the ear directly.
Should i first run pom in jar? does it not build that jar automatically when i build ear?
Create a multi module build that will build it all for you in the reactor. Read more about it e.g. http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html#pom-relationships-sect-multi-vs-inherit
I guess you should define tha .jar and .war projects as dependencies of your .ear project. It is also advisable to have a parent pom, where all the projects are defined as modules, including the .ear project.
In this book you can find a well explained step-by-step setup of a maven multimodule project (with downloadable code).
There is also a great working example of an enterprise multimodule project in the JBoss quickstart examples.

Creating EAR with Maven

project structure:
domain project (containing Pojos/Entities)
service project (EJB project)
service client project (interfaces for service project)
web project
ear project
parent project (just containing parent pom)
How do I have to configure the different poms?
Do I have to define dependencies like service project needs domain and service client project?
The structure of an generated EAR with Eclipse (export as EAR):
target
META-INF
lib (containing ServiceClient.jar,Domain.jar)
Service.jar (EJB project)
Web.war
pom.xml
How can I get this structure with Maven?
The Maven EAR plugin allows you to define the projects required in the various roles of your EAR. Have a look at the documentation. Naturally your sub-projects will need to refer to each other for compiling, but you can set their scope as provided to ensure you only get one copy of the jar in the built ear.

Resources