Failed to build multiple assemblies in maven. No assemby descriptor found - maven

I'm having some trouble when trying to generate two or more jars from a maven project when using the assembly plugin.
I have the following maven pom.xml file (see below).
However, when I run mvn clean compile assembly:single,
I get the following error:
Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project hyuga: Error reading assemblies: No assembly descriptors found. -> [Help 1]
What am I missing?
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>dg2cep</id>
<configuration>
<archive>
<manifest>
<mainClass>br.pucrio.inf.lac.konoha.hyuga.core.Bootstrap</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>dg2cep</finalName>
</configuration>
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>playback</id>
<configuration>
<archive>
<manifest>
<mainClass>br.pucrio.inf.lac.konoha.hyuga.others.csv.CSVPlayback</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>playback</finalName>
</configuration>
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Ah..you are executing it like this: mvn ... assembly:single ? If so don't do this.. use it within the life cycle like mvn clean package ....

Related

`java.lang.NoClassDefFoundError` from javaagent built by `maven package`

I've been trying to build javaagent (containing premain()) to .jar file using maven mvn package, and keep getting java.lang.NoClassDefFoundError exception related to external dependencies. For details, I added kafka-client dependecies and maven-jar-plugin to pom.xml like below
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
<Premain-Class>com.my.java.monitoring.Agent</Premain-Class>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
</manifestEntries>
</archive>
</configuration>
</plugin>
After reading How can I create an executable JAR with dependencies using Maven?, I tried using maven-assembly-plugin instead, like below
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Premain-Class>com.my.java.monitoring.Agent</Premain-Class>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
but I get this error =>
Failed to find Premain-Class manifest attribute in target/my-java-agent.jar Error occurred during initialization of VM agent library failed to init: instrument
Can anyone who has experience building javaagent .jar file with dependencies, please help.

Unable to obtain archiver for extension 'tgz'

I am seeing below error while executing TestNG test cases in Eclipse on my Mac. No idea how to resolve it.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (make-assembly) on project abc-services-tests: Failed to create assembly: Unable to obtain archiver for extension 'tgz' -> [Help 1]
Here is the code from pom.xml:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.xyz.openapi.RunTestNG</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Can some one please help me resolve this issue?
Resolved issue by doing maven clean install from terminal. somehow maven clean install from eclipse didn't work.

mvn output jar file is executable only inside target folder

I have a mvn built jar, which is working fine inside the target folder.
But if I copy the jar to different folder/machine.I get a class not found exception. I understand the jar is unable to access the dependencies. how can i fix this?
my pom contains,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.outputDirectory}/dependency/
</outputDirectory>
</configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.Main</mainClass>
<classpathPrefix>dependency/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
Thanks In Advance,
Saranya
Make a fat jar with dependencies using maven-assembly-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
The target folder would have additional jar-with-dependencies.jar; you should be able to use this anywhere.
I removed the maven jar and dependency plugins from my pom. Added
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.importer.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>xyz</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance
merges -->
<phase>package</phase> <!-- bind to the packaging phase
-->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
This created a jar with dependencies which can be executed anywhere. Also with the specific jar name.

How to avoid WARNING message "already attached to project, ignoring duplicate"

I've tried to avoid the maven warning message which comes from assembly plug in (I compile 2 jar files which are compiled from the same module)
Part of my pom.xml :
maven-jar-plugin
2.3.1
default-jar
none
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<id>MockFX</id>
<configuration>
<finalName>MockFX</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>mock.DSlauncher.FX.FX_DataSourceLauncher</mainClass>
</manifest>
</archive>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>MockFutures</id>
<configuration>
<finalName>MockFutures</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>mock.DSlauncher.Futures.Futures_DataSourceLauncher</mainClass>
</manifest>
</archive>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
During the compilation process I'm getting the next WARNING msg :
[WARNING] Artifact com.my.company:UAT-Mock:jar:jar-with-dependencies:1.0 already attached to project, ignoring duplicate
What should I add to pom.xml in order to avoid the warning ?
Thanks
Just add <attach>false</attach> to the configuration of both executions

How to call a descriptor from inside another descriptor in maven assembly plugin?

I want to create my own descriptor file in maven which will setup a zip file with a current directory structure. I would like for the jar of my project to be generated with dependencies which can be done by the built-in descriptor jar-with-dependencies.
My question is how can I tell my descriptor to call the jar-with-dependencies descriptor and include the generated jar instead of the normal jar?
You can configure sequence of maven assembly plugin executions:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>package-jar-with-dependencies</id>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>package-distribution-zip</id>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>bin</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>

Resources