Unpack and change bundle name of a EAR deployment - maven

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)

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.

OpenLiberty Maven Plugin

I am trying to create a runnale openliberty server as part of my release process. I have a a multi module maven project with a submodule dedicated to packaging the server as a runnable. When I do a mvn clean package a lovely executable jar is produced which bundles one of the other submodules (war). The problem I am facing is when I do a maven deploy to our asset repo the packaged server is being uploaded as a zip file rather than a jar file. Does anyone know how to get the deploy plugin to upload the jar?
Here is a sample pom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>au.com.xxxx.xxxx</groupId>
<artifactId>xxx-backend-parent</artifactId>
<version>0.0.16-SNAPSHOT</version>
</parent>
<artifactId>xxxx-openliberty-server</artifactId>
<packaging>liberty-assembly</packaging>
<name>fusion-openliberty-server</name>
<description>Runnable Jar containing xxxxand the OpenLiberty applictaion server</description>
<dependencies>
<!-- Package xxxx-application.war with server assembly -->
<dependency>
<groupId>au.com.xxx.xxx</groupId>
<artifactId>xxxx-application</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Enable liberty-maven-plugin -->
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>2.6.1</version>
<extensions>true</extensions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-javaee8</artifactId>
<version>18.0.0.3</version>
<type>zip</type>
</assemblyArtifact>
<include>runnable</include>
<serverName>xxx</serverName>
<appsDirectory>apps</appsDirectory>
<serverEnv>${basedir}/src/main/resources/server.env</serverEnv>
<configFile>${basedir}/src/main/resources/server.xml</configFile>
<jvmOptionsFile>${basedir}/src/main/resources/jvm.options</jvmOptionsFile>
<bootstrapProperties>
<app.context.root>xxx-app</app.context.root>
<default.http.port>5000</default.http.port>
<default.https.port>5443</default.https.port>
</bootstrapProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
I don't have an answer to your question but an explanation why this happens. Every packaging type (jar, war, liberty-assembly) defines a fixed extension for the artifact(s) it creates. The liberty-assembly types defines zip as it extension. This extension is used by the maven-install-plugin and maven-deploy-plugin regardless how the local file is names. I did quite some code digging but couldn't find a way to change this. It's probably sth. that only liberty-maven-plugin can change/fix.

Trouble converting EAR (and its WARs) to Maven

Today I thought it was a good idea to convert my projects into Maven projects.
I have an EAR that contains 4 WARs and 3 EJB-modules. I followed IBM's tutorial about migrating an EAR project. I ended up converting all my wars/ejb-jars one by one, and finally the EAR. I also added the war to the EAR as dependencies in the EAR's pom.xml. But when I launch the mvn ear:ear command it throws me a warning like this one :
[WARNING] The POM for server-admin-connector:server-admin-connector:war:0.0.1-SNAPSHOT is missing, no dependency information available
Then, the build fails because of this error :
[ERROR] Failed to execute goal on project server-ear: Could not resolve dependencies for project server-ear:server-ear:ear:0.0.1-SNAPSHOT: The following artifacts could not be resolved: server-admin-connector:server-admin-connector:war:0.0.1-SNAPSHOT
I think IBM's article is not complete, but I couldn't find any other source about migrating a whole EAR project to Maven. Can anyone help me on this? How can I get rid of this error?
EDIT : I don't have a particular project structure in my workspace. Here are my projects, however :
/server-project/
*server-ear (EAR)
*server-admin-connector (WAR)
*server-adminClient (JAR - stores the shared POJOs and interfaces for admin)
*server-business-layer (EJB)
*server-business-layerClient (JAR - stores the shared POJOs and interfaces for the business connector)
*server-business-connector (WAR)
I started converting the non-EAR projects, with their required dependencies. Then I used the maven ear module to add them all in the ear's POM.xml. Eclipse didn't show me any errors when doing this, so I assumed the build part was OK.
Here's the EAR's pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>server-ear</groupId>
<artifactId>server-ear</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<name>server-ear</name>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<generateApplicationXml>true</generateApplicationXml>
<applicationXml>${project.build.directory}/application.xml</applicationXml>
<skinnyWars>true</skinnyWars>
<version>7</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<ejbModule>
<groupId>server-business-layer</groupId>
<artifactId>server-business-layer</artifactId>
</ejbModule>
<webModule>
<groupId>server-admin-connector</groupId>
<artifactId>server-admin-connector</artifactId>
<contextRoot>/admin</contextRoot>
</webModule>
<webModule>
<groupId>server-intern-rest-connector</groupId>
<artifactId>server-intern-rest-connector</artifactId>
<contextRoot>/api</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>server-admin-connector</groupId>
<artifactId>server-admin-connector</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>server-business-layer</groupId>
<artifactId>server-business-layer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>server-intern-rest-connector</groupId>
<artifactId>server-intern-rest-connector</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>server-business-layerClient</groupId>
<artifactId>server-business-layerClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>server-adminClient</groupId>
<artifactId>server-adminClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
I found my problem. I wasn't installing every war/jar one by one. Don't forget to run the "mvn install" command on all WARs/JARs before trying to generate the EAR!
I don't know if I mark this as answer, or if i simply delete the question...

maven EAR plugin configuration

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>

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>

Resources