Trouble converting EAR (and its WARs) to Maven - 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...

Related

including test-jar in the runtime scope

i got a war-project and in the test-jar of it, we have aside of the jUnit testcases also the mocks to the neighbor systems (for instance, the roles and users management system).
and we have a maven profile called mocking that adds the test-jar dependency to the war-project, at runtime, so that the mocks are available for the developer, but do not end up by error in production.
<profile>
<id>mocking</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
...
not very clean, i know, but we did not want to have just another artifact for only a hand full of mock clases, and it worked so far well with Maven 3.3.9.
now we need a feature of Maven 3.5.0, so i updated to the latest Maven 3.6.2 and get following error:
The project com.my-project:web:0.0.1-SNAPSHOT has 1 error:
'dependencies.dependency.[com.my-project:web:0.0.1-SNAPSHOT]' for com.my-project:web:0.0.1-SNAPSHOT is referencing itself.
which is kind of borderline case.
imho, and since the dependency is of scope runtime, it should be allowed.
is this a bug?
can anyone figure out a better way to achieve this?
many thanks
Michael
UPDATE 20191125:
Without full pom files or at least an example which looks very like your original projects it's hard to guess....
Here a small pom-file to reproduce the problem:
<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>my.project</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
with that file, and nothing else, mvn compile works fine with v3.3.9 but breaks with v3.6.2
If you use the normal setup for creating a test-jar this implies the test-jar is created as supplemental artifact to your usual artifacts which needed to be distinguished from each other which has to be achieved by using the <classifier>tests</classifier>.

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.

Cannot include project artifact: com.test.mmm.jar:1.0; it doesn't have an associated file or directory

I'm pretty lost with maven and I can't seem to find a solution for my problem. When I try to generate the jar file with all the dependencies of my project to execute it on another computer I find this warning when I execute sudo mvn clean compile assembly:single:
[WARNING] Cannot include project artifact: com.test:mmm:jar:1.0; it doesn't have an associated file or directory.
Also, when I try to execute the .jar with java -jar target/test.jar this error appears:
Error: Unable to access jarfile target/test.jar
here's my 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>com.test</groupId>
<artifactId>mmm</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>mmm</name>
<url>http://maven.apache.org</url>
<properties>
<nd4j.backend>nd4j-cuda-8.0-platform</nd4j.backend>
</properties>
<dependencies>
<dependency>
<groupId>org.jblas</groupId>
<artifactId>jblas</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.test.mmm.Main</mainClass>
</manifest>
</archive>
<finalName>test</finalName>
<descriptorRefs>jar-with-dependencies</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
The main class is located in src/
I've tried many solutions from stack overflow but had no success, can someone help me?
Thank you!
Use mvn package first to build your module classes then assembly:single.
mvn package assembly:single
From the warning you've included in your question:
[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated.
I'd guess that you've got the packaging in your pom.xml set to pom.
This is fine if your module is simply packaging a set of dependencies or resource files, however, if you also want Maven to create a jar containing the classes in you module you will need to set the packaging to jar.
make sure that your atrifact produced is matching with <finalName>
i.e.
<groupId>com.rocket</groupId>
<artifactId>myapp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>myapp</name>
produces myapp-1.0.jar
and provide same here
<finalName>myapp-1.0</finalName>
and run then execute:
mvn package assembly:single

A required class is missing: org.apache.maven.plugin.jar.JarMojo

After I upgraded my Ubuntu to 13.10 version I reinstalled the latest Eclipse Kepler.
I have a simple JSE app. It used to work in Eclipse before and it's still working through terminal (mvn clean install), but now I'm getting an error in Eclipse:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar
(default-jar) on project files: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar
failed: Unable to load the mojo 'jar' in the plugin 'org.apache.maven.plugins:maven-jar-plugin:2.3.2'.
A required class is missing: org.apache.maven.plugin.jar.JarMojo
I already tried a few things:
I checked jvm version configured in eclipse.ini: -vm /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
I tried 3.0.5 and 3.1.1 maven versions;
I right-clicked the project and selected Maven->Update Project.
I checked the java version in the project properties menu: it's pointing to /usr/lib/jvm/java-6-openjdk-amd64, although it always changes back to JavaSE-1.6(jre6) after I follow the previous step (Update Project).
Set java source and target version to 1.6 in the maven-compiler-plugin in pom.xml configuration.
Tried different jdk versions (openjdk6, openjdk7, oracle jdk6 and oracle jdk7);
I also tried to download JBoss Devstudio and also cleaning workspace by deleting .metadata folder.
Unfortunately nothing worked.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>br.uel.ati.util</groupId>
<artifactId>files</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jse-template</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<description>Template da Diretoria de Desenvolvimento de Sistemas para bibliotecas utilizadas por projetos EJB e Web.</description>
<organization>
<name>Universidade Estadual de Londrina</name>
<url>http://uel.br/ati</url>
</organization>
</project>
Anyone know what I should try to solve this issue?
I found the solution here: How can i resolve plugin problem in maven:' Unable to load mojo'
Apparently there was a corrupted library in maven repository. I just deleted repository/org folder, download it again and updated (Maven->Update Project + F5) my maven projects inside Eclipse.
I'm still curious about why it was working by command line. Maybe a new maven repository was created when I installed it by apt-get.

Maven descriptor (META-INF/maven) duplicate entry in archive

I'm facing a problem with maven build. I have several ejb projects. After maven build the jar-file contains the maven descriptor in META-INF/maven twice, i.e. if I extract files to disk 7zip asks to overwrite files although extracted to a new folder. If a specify <addMavenDescriptor>false</addMavenDescriptor> in the archive-tag of the ejb plugin then the maven decriptor is still generated but only once. Is there another place where I can disable maven descriptor generation or does anybody know the reason for the duplicate generation?
Maven version is: 3.0.3
Project structure is like:
-pom
-ejb
Here is the pom.xml of the EJB module:
<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>
<artifactId>TestMavenDescriptors</artifactId>
<groupId>de.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>TestEJB</artifactId>
<packaging>ejb</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Here is the pom.xml of the parent project.
<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>de.test</groupId>
<artifactId>TestMavenDescriptors</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>TestEJB</module>
</modules>
</project>
I found out that this is a problem special to eclipse version (I have RAD 8 trial) and possibily of the m2e plugin version. The above behavior (duplicate generation of maven descriptors) occurs only if I have the EJB project in my workspace added. That means if I remove the EJB project from workspace (without deleting contents on disk) such that only the hierarchal parent maven project (pom packaged) is existing in the workspace (which contains the EJB project but EJB project is then not known to eclipse) then everything works fine. Strange, isn't it?!
BTW: on current eclipse (java ee package) this doesn't occur, all fine there.

Resources