Creating EAR with Maven - 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.

Related

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

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.

include application-properties from multiple modules in maven multi-module spring-boot executable jar

we have a maven multi-module pom project with a core-module where i want to keep common application.properties, like database-access, email-gateways etc. Is it possible to integrate those application*.properties in the executable jar of the other modules as well (jars built by spring-boot-maven-plugin)?
when taking a look into the built jar, you can see that only the module's resources are integrated, all other modules are ignored.
Thanks

Gradle gather all jar dependencies in multi project and build a ear

I am pretty new to gradle and I am trying to achieve the following
I have setup a multi project build, with the following structure
root:
:commonjar (java-library)
:war1 (war)
:war2 (war)
:externaljars (local repository for unmanaged jars)
:libs (ear)
I would like to automatically gather all runtime dependencies for commonjar, war1 and war2 and generate a deployable ear (libs) where all jars are stored inside libs.ear/lib
I have kind found a way to gather all jar using taks definition like this:
task copyDeps(type: Copy) {
from(subprojects.configurations.runtime)
into project.file(libDirName)
}
But no matter where I store the jars, the get not picked up by the "ear" task.
Just to explain, I need to make a dummy ear, with only jars to do remote deployment and create shared library definitions on IBM Websphere application server.
Any good suggestion to have an ear gather and package all jars (transitive as well) used in the entire project?
Thanks
You can simply configure the ear task to include the dependencies you want to have in there with something like
ear {
duplicateStrategy = DuplicateStrategy.EXCLUDE
lib {
from rootProject.subprojects.configurations.runtime
}
}

Building/deploying a EJB .jar with its dependencies

I am new to Java EE. I use Maven, Eclipse and jBoss/WildFly.
I have a war project. When I build the project all its dependencies are packaged inside the war file in WEB-INF/lib.
Now I am trying to create a ejb project (I have <packaging>ejb</packaging> in the pom.xml). I want to deploy it as a separate project (not as a part of the war). When I build the ejb project Maven does not package any dependencies in the jar.
How can I package/deploy a ejb .jar with its dependencies?
UPDATE: I'd like to avoid packaging EJBs in an .ear if it is possible. (I do not want to create one more Maven project).
The best solution is package your project as ear. But if don't want use ear, maven assembly plugin can help you to package all needed jars in one file. This solution is only for "proof of concept" variant, and cannot be used in production mode, by licences limitation for example.

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