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

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.

Related

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.

Lib folder gets packaged with eclipse plugin jar while building through tycho

I am trying to build eclipse plugin using tycho-compiler-plugin from maven.
I have resolved many bundled dependencies from p2 repo. I have some jar dependencies which are present in bundle-classpath in manifest.mf -
Bundle-ClassPath: .,
lib/test1.jar,
lib/test2.jar
These jars are present in lib folder which is present at root level i.e where pom is present.
POM file looks like -
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>com.test.plugin</artifactId>
<version>0.0.0</version>
<packaging>eclipse-plugin</packaging>
<repositories>
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>file:///E:/repo/eclipseRepo/</url>
</repository>
</repositories>
<build>
<directory>../../../../target</directory>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.25.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>0.25.0</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>0.25.0</version>
<configuration>
<buildDirectory>../../../../plugin</buildDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now ti builds eclipse plugin properly , but while packaging it also includes lib folder. Attached jar screenshot -
I want to exclude this lib folder from jar.I have tried configuration in tycho-packaging-jar plugin to exclude it. But not working. How to exclude it?
Using a <directory> or <buildDirectory> outside the current project’s base directory looks fairly non-standard. In fact, I have never had the need to explicit configure either of these – or <sourceDirectory>, for that matter. That’s what the build.properties file is for, which is the default way to configure these things in both Eclipse PDE and Tycho.
From the screenshot it looks like there is no build.properties file present. I would suggest you configure the various locations through its properties rather than through POM elements. Something along the lines of this example, with bin.includes and bin.excludes handling your JAR inclusions.

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 : 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>

Resources