Unable to obtain archiver for extension 'tgz' - macos

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.

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.

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

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

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

Maven : Dependencies Management

I already saw lot of post related to this question, but hard to figure out the best approach of doing this. I am having a maven project having two dependencies (A.Jar) and (B.Jar) in maven central repostories. I want to create a runnable jar. Which is the best approach in doing this and how to do this ? An example will be helpful. (sample POM.XML)
thanks !
The simplest solution would be to use maven-assembly-plugin via a predefined descriptor:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</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>
</plugins>
</build>
Via the above you can do simply:
mvn clean package
which results in having a file target/whatever-1.0-SNAPSHOT-jar-with-dependencies.jar which is exactly what you like to get.

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