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

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

Related

How to make Quarkus use local library classes

I'm starting with Quarkus using Maven and can't seem to find a solution to this:
I have a Quarkus app with dependencies on the libraries A and B. Both are imported as "Modules" (not Maven modules!) in the IntelliJ IDEA project for my app.
When starting Quarkus in dev mode, it ignores the classes in target/ of A and B and instead loads them from the Maven repository. Therefore with every change in either A or B, I have to mvn install the respective library, so my Quarkus app uses the correct code.
Coming from Thorntail, this was not necessary. Is there a solution that doesn't require auto-installing A and B on every build and also makes HotSwap work for those libs?
Edit:
As #CrazyCoder requested, here's a minimal example of 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>com.example</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<quarkus-plugin.version>1.8.3.Final</quarkus-plugin.version>
<quarkus.platform.version>1.8.3.Final</quarkus.platform.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>A</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
A and B are listed in IntelliJ IDEA under "Project Structure... > Modules > test > Dependencies" as Module Depenencies, not Maven Dependencies. So the code in A and B should be HotSwappable.
I eventually found the solution. As so often: Once you know it, it's trivial.
Open your run configuration, expand the Environment dropdown (only populated when an application module is selected) and check the option Resolve Workspace artifacts:

Maven Failed to Execute Goal org.apache.maven.plugins:maven-surefire-plugin2.22.2 And maven-compiler

I get some errors when I try to run the maven test in Intellij. When I try to run the test from maven I get the following maven-sunfire error :
"Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin". I updated my pom.xml file to different maven-sunfire-plugin versions...
Also when I use the following command : mvn clean install -U , I also get an error.
"[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on proje
ct AnimalShelter: Fatal error compiling: invalid flag: --module-path -> [Help 1]"
I just want to run the test via maven, I tried so many things but maven just won't work. My test are fine, I tested them solo and together via "Run all tests". Just in Maven it won't work.
I searched alot and also tried to delete the .m2 file. Also not working.
I use java version 12
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>nl.julianlu</groupId>
<artifactId>AnimalShelter</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<printSummary>true</printSummary>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
My module-info.java
module AnimalShelter {
requires javafx.controls;
requires javafx.fxml;
opens ui;
exports ui;
exports classes;
exports Interfaces;
}

Not include src/lib/*.jar in war file

I want when run
mvn verify
to include all files from /lib/ folder to war archive in folder 'web-inf/lib`
So here 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>com.myhost</groupId>
<artifactId>sailero</artifactId>
<name>myapp</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>com.host</groupId>
<artifactId>some-lib</artifactId>
<scope>system</scope>
<version>0.0.1</version>
<systemPath>${project.basedir}/lib/some-lib-0.0.1.jar</systemPath>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<configuration>
<packagingIncludes>lib/*.jar</packagingIncludes>
</configuration>
</configuration>
</plugin>
in console:
mvn verify
But in war NOT INCLUDE some-lib-0.0.1.jar
in war in \target\myapp-1.0-SNAPSHOT.war\WEB-INF\lib\ -> not exist "some-lib-0.0.1.jar", but all other dependencies included.
Maven war plugin automatically copies all the project dependencies into WEB-INF/lib. So if your war needs a dependency just put the relevant GAV into the dependency section of this module.
Example:
In your pom, you have a dependency on:
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.7.0</version>
</dependency>
So it will be automatically included appear in WEB-INF/lib of your WAR.
Now it doesn't work like this with dependencies in scope system and this is a root cause of the issue here.
Long story short, this question has been already asked/answered in SO.
Bottom line, I suggest getting rid of system dependency and placing it at least in the local repo or ideally in some proxy like Nexus or Artifactory. But of course, you're welcome to test other approaches suggested in the provided link.
This fix problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webResources>
<resource>
<directory>lib</directory>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
Here correct approach:
first install "some-lib-0.0.1.jar" in local maven repo:
mvn install:install-file -Dfile=myproject\lib\some-lib-0.0.1 -DgroupId=com.host -DartifactId=some-lib -Dversion=0.0.1 -Dpackaging=jar
and second in pom.xml
<dependency>
<groupId>com.host</groupId>
<artifactId>some-lib</artifactId>
<version>0.0.1</version>
</dependency>
Also I found another approach:
Create a “lib” folder under your project like this: “\src\main\webapp\WEB-INF\lib”
Copy needed “jars” etc that you want included inside your WAR bundle folder.
Invoke your maven build as you normally do. I use “mvn install”, which creates builds the war file

Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.7

I was developing a project on JBoss-Fuse from Create a Router Project.
While running mvn -install , I am getting following error:
[ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.7:bundle (default-bundle) on project camel-basic: Error calculating classpath for project MavenProject: org.fusesource.example:camel-basic:1.0-SNAPSHOT # /home/pr.singh/Gemini/Java-General/Workspace/fuse/camel-basic/pom.xml: The JAR/ZIP file (/home/pr.singh/.m2/repository/org/apache/camel/camel-jetty/2.17.0.redhat-630187/camel-jetty-2.17.0.redhat-630187.jar) seems corrupted, error: invalid END header (bad central directory offset) -> [Help 1]
I exactly following the redhat tutorial, I am unable to debug the problem. Please help.
My pom.xml is :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>org.fusesource.example</groupId>
<artifactId>camel-basic</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>JBoss Fuse Quickstart: camel-cbr</name>
<description>Camel Content-Based Router Example</description>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.compiler.plugin>2.3.1</version.compiler.plugin>
<version.maven-bundle-plugin>2.3.7</version.maven-bundle-plugin>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<!-- the version of the BOM, defining all the dependency versions -->
<fabric8.bom.version>1.2.0.redhat-630187</fabric8.bom.version>
<fabric.version>1.2.0.redhat-630187</fabric.version>
<!-- fabric8 deploy profile configuration -->
<fabric8.profile>camel-basic-profile</fabric8.profile>
<fabric8.parentProfiles>feature-camel</fabric8.parentProfiles>
<fabric8.features/>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.fabric8.bom</groupId>
<artifactId>fabric8-bom</artifactId>
<version>${fabric8.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--
For this example, we will be using the OSGi Blueprint XML syntax for Apache Camel.
-->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${version.maven-bundle-plugin}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<!--
this plugin will use the fabric.* properties to configure its behaviour
see the Properties section here: http://fabric8.io/gitbook/mavenPlugin.html
-->
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${fabric.version}</version>
</plugin>
</plugins>
</build>
</project>
After digging a bit about the issue, I found the solution to it.
After reading the line of error code that says:
Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.7:bundle
I thought there is some issue with org.apace.felix, but later I paid attention to the line of error that was stating :
The JAR/ZIP file (/home/pr.singh/.m2/repository/org/apache/camel/camel-jetty/2.17.0.redhat-630187/camel-jetty-2.17.0.redhat-630187.jar) seems corrupted
Issue:
So the issue was that my camel-jetty jar was corrupted.
Solution:
I simple navigated to /home/pr.singh/.m2/repository/org/apache/camel and deleted camel jetty.
Run mvn clean install on project and new file with name camel jetty was created (maven installed this plugin). And error was gone.

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

Resources