maven EAR plugin configuration - maven

i have problem with ear plugin configuration, exactly i want to place one of jar dependency in root directory in ear and rest of them in lib directory. Can someone help me with this?
Update:
I have 4 projects, one of them is a container, pom type. One of them is a ear with two dependencies, war and jar. I want to create ear with directory structure:
/ - a.war and b.jar projects
/lib/ - all dependencies for 'a' and 'b' projects
/META-INF/ - MANIFEST.MF
part of pom.xml
<configuration>
<!-- <artifactTypeMappings>
<artifactTypeMapping type="war" mapping="webModule" />
</artifactTypeMappings> -->
<webModule>
<groupId>a</groupId>
<artifactId>a</artifactId>
<contextRoot>/a</contextRoot>
<bundleFileName>a.war</bundleFileName>
<bundleDir>lib</bundleDir>
</webModule>
<jarModule>
<groupId>b</groupId>
<artifactId>b</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>/b.jar</bundleFileName>
</jarModule>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>

A simple look into the documentation would have helped. You just remove the bundleDir entry from the entry you like to place into root location.
<jarModule>
<groupId>b</groupId>
<artifactId>b</artifactId>
<bundleFileName>/b.jar</bundleFileName>
</jarModule>

Related

Maven EAR plugin: Generated EAR file does not contain WAR or EJB or RAR modules

I've been using the EAR plugin to package a WAR, EJB & RAR module, however, while they all package successfully when i run mvn clean package, I notice the following gets output in the target directory.
application.xml (generated application.xml)
my-application-ear-1.0-SNAPSHOT (directory with correctly packaged WAR, EJB & RAR dependencies, META-INF with generated application.xml and additional resources from the EAR project)
my-application-ear-1.0-SNAPSHOT.ear (9kb .ear file that only has the META-INF with the generated application.xml & additional resources from the EAR project)
None of the modules are packaged in the final EAR file.
Here is the <build> node of the EAR project's POM.
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<finalName>my-application-ear</finalName>
<version>7</version>
<earSourceDirectory>src/main/application</earSourceDirectory>
<packagingIncludes>**/*</packagingIncludes>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<filtering>false</filtering>
<packagingIncludes>Default_HTTP_WC/**,Default_IIOP_WC/**,Default_JMS_WC/**,META-INF/**,</packagingIncludes>
<modules>
<ejbModule>
<groupId>com.abc.def</groupId>
<artifactId>ejb-module</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>ejbModule.jar</bundleFileName>
<moduleId>EjbModule_1</moduleId>
</ejbModule>
<rarModule>
<groupId>com.abc.def</groupId>
<artifactId>rar-module</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>RARModule</bundleFileName>
<uri>/RARModule.rar</uri>
<unpack>true</unpack>
<moduleId>RARModule_1</moduleId>
</rarModule>
<webModule>
<groupId>com.abc.def</groupId>
<artifactId>my-web-app</artifactId>
<uri>/WebApplication.war</uri>
<bundleDir>/</bundleDir>
<bundleFileName>WebApplication.war</bundleFileName>
<contextRoot>/foo</contextRoot>
<moduleId>WebModule_1</moduleId>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</plugin>
</plugins>
Am i missing something? Any assistance is appreciated.
I figured out my problem, I had completely overlooked the use of <packagingIncludes> from an earlier iteration. removed it and its fine.

Unpack and change bundle name of a EAR deployment

Migrating from Maven to Gradle I'm struggle to find a way to port following Maven configuration block
of the "maven-ear-plugin" Maven plugin:
<webModule>
<groupId>my.group</groupId>
<artifactId>MyArtifact</artifactId>
<bundleFileName>my-artifact-v1.war</bundleFileName>
<contextRoot>/v1</contextRoot>
<unpack>true</unpack>
</webModule>
<webModule>
<groupId>my.group</groupId>
<artifactId>MyArtifact</artifactId>
<bundleFileName>my-artifact-v2.war</bundleFileName>
<contextRoot>/v2</contextRoot>
<unpack>true</unpack>
</webModule>
Here I need to deploy a single artifact twice under different bundle names. Besides that, both deployments should be unpacked (within the EAR file).
How could this Maven configuration block be ported to Gradle 'ear' plugin.
(Kotlin notation would be great)

Maven : Remove duplicate jars from EAR

We are using maven to build an EAR that contains WAR, the JARS are duplicated on both EAR's root and WAR's lib folder, I read about the skinny jars to remove the jars from the WAR but I don't want this as I want to keep the WAR as stand alone unit,
IS there a way to do it the other way around and remove the JARs from the EAR's root folder ?
attached is the EAR POM
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<modules>
<webModule>
<groupId>com.csv.xyz</groupId>
<artifactId>web</artifactId>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.csv.xyz</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
<scope>compile</scope>
</dependency>
</dependencies>
The "maven-skinny-war" solution isn't any drawback in your case. Also have a look at this question and my answer: How to make maven place all jars common to wars inside the same EAR to EAR root?
With this solution you will first get WARs packaged with their own dependencies and second, an EAR module with skinny WARs. So everything is deployable on its own and nothing is duplicated.
I don't think this would be a good idea because of the class loader architecture. If a JAR is part of a WAR, it's defined by the web app class loader, which may result in multiple instances. If it's part of an EAR, it's defined by the enterprise app class loader, which is a different class loader.
To remove a dependency from the EAR lib folder, declare the dependencies as provided in the EAR pom, for example to remove commons-lang:
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
Just make sure if you have EJB modules that they don't require the dependency! Also webModules do not contribute to the EAR's root lib folder, do you have more dependencies in you ear pom?

How to exclude jars from ear

I am bundling EAR from a WAR file. The JARS are placed both in WARFile/WEB-INF/lib folder as well as EARFile/lib folder with duplication.
Do we need the JARS again in EARFile/lib folder inspite of having in WARFile/WEB-INF/lib?
If we do not need in EAR/lib filder, How can we remove them? The EAR file size became double due to duplication JARs presence in both WAR and EAR.
Please help me.
Thanks
Good read here on "skinny" wars. Basically, you put the jars in the ear, but not the war files:
http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
You have to define the dependency to your war project in the following way:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>xyz-web</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
and furthermore you have to configure the ear plugin like the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>6</version>
<modules>
<!-- Register our War as a web module, and set the context root -->
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>xyz-web</artifactId>
<contextRoot>/xyz</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>

creating war file using maven-ear-plugin and defining it in one pom.xml

I am at the starter level of the maven usage. I hope I can explain my problem clearly, I want to create an ear file which contains war file inside it. And I planned to use to create a war file from the start. Also I want to do it in my pom.xml at my project and there is only one pom.xml, here is the problem;
Can I create ear file and which contains this war that I created at the same time in one pom.xml file?
when I try to create war file in webmodule tag, here is the problem that I encounter " Artifact[war:denem.denem:denem] is not a dependency of the project." I understood so that's why I added dependency for this file in the same pom.xml but this time I encountered that problem
(By the way my command to build this pom is "mvn clean package" )
"1 required artifact is missing.
for artifact:
com.denem.denem:com.denem.de2:ear:v0.1"
It tries to find this war file but I want to create it not to find it. Here the code in my pom.xml file;
<parent>
<groupId>denem.denem</groupId>
<artifactId>com.denem.denem</artifactId>
<version>v0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>denem.denem</groupId>
<artifactId>com.denem.de2</artifactId>
<version>v0.1</version>
<packaging>ear</packaging>
<properties>
<cxf.version>2.2.5</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>denem.denem</groupId>
<artifactId>denem</artifactId>
<version>v0.1</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.5</version>
<configuration>
<finalName>edu</finalName>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>denem.denem</groupId>
<artifactId>denem</artifactId>
<contextRoot>/WebContent</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
I guess I am doing lots of things wrong. But If you can help me I will be glad. Thank you anyway.
You need to create a modular project.
Create:
a parent project of type "pom";
a child project of type "war";
if needed, child projects of type "ejb";
if needed, child projects of type "jar" (common libraries);
one project of type "ear", that has all of the above as dependencies.
In the latter you need to configure the ear plugin putting all the modules that you need.

Resources