maven assembly plugin tgz - no such archiver - maven

I need to do a really simple tar action using the maven-assembly-plugin.
My file extension must be .tgz not tar.gz
Here is my pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.artifactId}</finalName>
<descriptors>
<descriptor>dist-all.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
and here is my assembly description file
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>default-cli</id>
<formats>
<format>tgz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/app</directory>
<outputDirectory>target</outputDirectory>
</fileSet>
</fileSets>
</assembly>
when I run mvn clean install it generates the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (default-cli) on project my-app: Failed to create assembly: Unable to obtain archiver for extension 'tgz', for assembly: 'default-cli': No such archiver: 'tgz'. -> [Help 1]
[ERROR]
According to the maven page I am allowed 'tgz' format.
https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
What have I missed?
I'd be grateful for any help,

Related

creating a tar archive from maven deploy

I am trying to use maven v3 to create a tar.gz output for a non-Java project in order to deploy to nexus. I cannot specify tar in the packaging option in my pom file. Unless mistaken, I can specify tar as an option for packaging when running mvn deploy. Is there anyway I can specify that in the pom file itself?
You can create the TAR.GZ file and "attach" it to the primary artifact. I have an example to repackage a WAR into Linux service on GitHub. The key steps are to package the assembly:
<project ...>
...
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
<formats>
<format>tar.gz</format>
</formats>
<descriptorSourceDirectory>src/main/assemblies</descriptorSourceDirectory>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
...
</plugins>
</build>
</project>
<attach>true</attach> installs the artifact. The assembly in this case is:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>bin</id>
<baseDirectory>${artifactId}-${version}</baseDirectory>
<files>
<file>
<outputDirectory>bin</outputDirectory>
<source>
${project.build.directory}/${project.build.finalName}.jar
</source>
<filtered>false</filtered>
<destName>${artifactId}.jar</destName>
</file>
</files>
<fileSets>
<fileSet>
<outputDirectory>bin</outputDirectory>
<directory>${project.basedir}/src/bin</directory>
<includes>
<include>${artifactId}.conf</include>
</includes>
<filtered>true</filtered>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>*:*-x86_64:*</include>
</includes>
<scope>runtime</scope>
<outputFileNameMapping>
lib${artifact.artifactId}.${artifact.type}
</outputFileNameMapping>
</dependencySet>
</dependencySets>
</assembly>
but you'll need to find/create one appropriate for your use-case.

maven-assembly-plugin loops over each module without being told to do so

I am just trying to copy some files into some directories, and using this plugin since I am told that it is convenient. However, whenever I try to do mvn install, the plugin somehow tries to loop over every module in my pom.xml (I never asked it to do this kind of thing) and tries to do some operation, then gives the error of :
Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-install-assembly) on project untoldProject Failed to create assembly: Error creating assembly archive install: You must set at least one file.
I want this plugin to operate on only certain modules (and folders which are not modules) which I already specify in the path, in the assembly file of mine. So I don't know why is the plugin tries to do this operation for every module.
Here is my pom.xml where I use the plugin:
<!-- This plugin is used to copy the necessary files to project.release/install folder -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-install-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>true</inherited>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
Here is my asssembly.xml where I specify what I want to copy:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>install</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>project.release/template</directory>
<outputDirectory>project.release/install</outputDirectory>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<includes>
<include>run.all.sh</include>
<include>kill.all.sh</include>
<include>packlogs.sh</include>
</includes>
<excludes>
<exclude>config.properties</exclude>
<exclude>run.all.ant</exclude>
<exclude>run.ant</exclude>
<exclude>packlogs.sh</exclude>
<exclude>install.sh</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
Given this, why does the plugin try to do this operation for every module? I just want it to happen for one module, called project.release, and that's it. I put both of my pom.xml and assembly.xml to the parent directory, for your information.
Update: For those who would like to see my project hiearchy, here is my master 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>runtime_project</groupId>
<artifactId>runtime_project.master</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<modules>
<module>project.messages</module>
<module>project.base</module>
<module>project.logging</module>
<module>project.mission.launch</module>
<module>project.mission.detach</module>
<module>project.settingsStore</module>
</modules>
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- This plugin is used to delete the contents of the project.release/install folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>project.release/install</directory>
<followSymlinks>false</followSymlinks>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- This plugin is used to copy the necessary files to project.release/install folder -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-install-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>true</inherited>
<configuration>
<descriptors>
<descriptor>deploy.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Given this, why does the plugin try to do this operation for every
module?
Because this is the nature of multi module project.
I just want it to happen for one module, called project.release, and
that's it. I put both of my pom.xml and assembly.xml to the parent
directory, for your information.
I give some hints, not a complete solution.
create an additional module called project.release. Add it to the <modules> element in the root POM. The order doesn`t matter
move the plugin-entry for the maven-assembly-plugin from the root POM to the POM of project.release
In the POM of project.release, add dependencies to other modules as necessary.
In the folder of project.release, place the assembly descriptor in src/main/assembly . The directory entries within your descriptor should be relative to the module root of project.release

How to deploy only zip artifacts in maven

I have done some zip packaging in maven using the below descriptor and pom file. But in maven by default it created both jar and zip in target folder. Now i want to deploy only zip contents where i am using deploy:deploy-file plugin. but it is not deploying instead it is showing error. Not sure what is wrong with tag and how it should be resolved.
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>
<groupId>com.wyndhamvo.prototype.dbscripts</groupId>
<artifactId>DB_SCRIPTS</artifactId>
<version>2.0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<snapshotRepository>
<id>wvoNexus</id>
<file>${project.artifactId}-${project.version}.zip</file>
<url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>wvoNexus</id>
<file>${project.artifactId}-${project.version}.zip</file>
<url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
</project>
assembly plugin descriptor file:
<assembly>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>DB_Files</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Command Executed:
mvn -X clean package deploy:deploy-file
Error:
[ERROR] Malformed POM C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml: Unrecognised tag: 'file' (position: START_TAG seen ...<id>wvoNexus</id>\r\n\t\t\t<file>... #37:10) # C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml, line 37, column 10
First you have to fix you error in distributionManagement area like this:
<distributionManagement>
<snapshotRepository>
<id>wvoNexus</id>
<url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>wvoNexus</id>
<url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
If you fixed that you can simple deploy the files to your nexus via:
mvn clean deploy
If you don't like having a jar deployed as well you need to change the packing type in your pom like this:
<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.wyndhamvo.prototype.dbscripts</groupId>
<artifactId>DB_SCRIPTS</artifactId>
<version>2.0.0.1</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Furthermore i recommend to define the versions of your used plugins like this:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
You made a mistake: the <file/> element is not a part of <snapshotRepository/>, it's an config item of deploy plugin! you should deploy your zip file as following:
mvn -X clean package deploy:deploy-file -Dfile=/path/to/your-artifact-1.0.zip

Package Dll in Jar using Maven- single goal

I have added a DLL in my maven project as dependency like this :
<dependency>
<groupId>com.test.dll</groupId>
<artifactId>myDll</artifactId>
<version>0.1</version>
<type>dll</type>
</dependency>
When I try to execute maven:install
It is giving me this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-
beta-5:single (jar-with-dependencies) on project testApp: Failed to create
assembly: Error adding file-set for 'com.test.dll:myDll:dll:0.1' to archive: Error
adding archived file-set. PlexusIoResourceCollection not found for: C:\Users\USER\.m2
\repository\com\test\dll\myDll\0.1\myDll-0.1.dll: No such archiver: 'dll'
What Am I doing wrong here??
Update
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>src/main/keystore/mykey.keystore</keystore>
<alias>aliasname</alias>
<storepass>passw0rd</storepass>
<verify>true</verify>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
The problem here is the jar-with-dependencies descriptor. The descriptor unpacks all dependencies into a directory and packages this directory into a new JAR file. However, it cannot unpack a DLL file (that's the "No such archiver" error message). To get this working, you need to define your own assembly descriptor:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>assembly-with-dll</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!-- package the regular dependencies -->
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<!-- exclude the DLL -->
<excludes>
<exclude>com.example:my-dll</exclude>
</excludes>
</dependencySet>
<!-- package the DLLs -->
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<include>com.example:my-dll</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
Provided, that the descriptor above resides in src/main/assembly, the configuration of the maven-assembly-plugin looks as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
There is a piece of information here : Maven Dll Dependency Problem.
To solve this issue, exlude dll from your assembly :
<excludes>
<exclude>*:dll*</exclude>
</excludes>
Last time I had to create a executable jar with dependencies, I put them out of the jar, in a lib directory.
DLL must be :
either in application classpath (like server/lib for a server)
or in the OS classpath (C:\Windows\system32 for instance)
After reading your pom and dependecy file set, I may be able to be more accurate :)
To add to Stefan's answer, I don't think you want to do a jar-with-dependencies packaging for this project of yours. You should look at using one of the bin packaging (like .zip or tar.gz)

maven assembly dir with a jar dependency from project

I am trying to use maven to assemble a directory for a install package. The install package requires several things: configuration files, dependency libraries and an executable jar of my class files. I am having trouble figuring out how to add the executable jar.
Here is what I have so far:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject</artifactId>
<version>8.1.1</version>
<name>my project</name>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<configuration>
<descriptor>${basedir}/src/main/assembly/client.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-client</id>
<configuration>
<descriptor>${basedir}/src/main/assembly/client.xml</descriptor>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
.
.
.
</dependencies>
</project>
Then my assembly descriptor looks like this:
<assembly>
<id>client</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/src/main/reports</directory>
<outputDirectory>/reports</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/resources/audio</directory>
<outputDirectory>/audio</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/client</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</assembly>
If i call mvn assembly:assembly I get a directory with all the libraries and configuration files. Works great.
But now I want to add an executable jar of all my compiled code. I can create this jar alone by adding this to my pom and calling mvn jar:jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>run</finalName>
<archive>
<manifest>
<mainClass>com.myproject.main.StartProcess</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
The question is, how can I get that jar into my assembly automatically?
I have tried a couple things but I have no idea where to start. Can I somehow call the jar execution from my assembly?
Any help appreciated.
I think you should turn your useProjectArtifact to true (this is the default value).
It determines whether the artifact produced during the current project's build should be included in this dependency set.

Resources