Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-assembly-plugin: How to change the output directory?

I want to create a zip file containing the jar files and some resource files. But I have some problems to tell the assembly plugin to take files from a source folder and to put it into a target folder without retaining the sources folder structure.

In detail: My files are placed in ../target/lib and they should be zipped to ../app/lib. This is an extract from my xml file which should do that job:

    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>app/lib</outputDirectory>
      <includes>
        <include>target/lib/*.*</include>
      </includes>
    </fileSet>

But what happens is: The files are placed to ../app/lib/target/lib/

How can I tell the maven-assembly-plugin to omit the source file structure and just take the files?

like image 788
Uwe Andersen Avatar asked Apr 27 '17 09:04

Uwe Andersen


People also ask

What is fileset in Maven?

Defines the rules for matching and working with files in a given base directory.

How does Maven Assembly plugin work?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.

What is assembly descriptor in Maven?

So in order for you to customize the way the Assembly Plugin creates your assemblies, you need to know how to use the Assembly Descriptor. This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly.

What is tarLongFileMode?

tarLongFileMode: Sets the TarArchiver behavior on file paths with more than 100 characters length. Valid values are: "warn" (default), "fail", "truncate", "gnu", "posix", "posix_warn" or "omit".


2 Answers

Directory must point to the folder of which all paths (both files and directories) must be copied. So you should do this:

<fileSet>
  <directory>${project.basedir}/target/lib</directory>
  <outputDirectory>app/lib</outputDirectory>
  <includes>
    <include>*.*</include>
  </includes>
</fileSet>
like image 160
Robert Scholte Avatar answered Oct 11 '22 12:10

Robert Scholte


Managed to fix it by setting the "directory" parameter to the source path and removing the source path information from "include":

    <fileSet>
      <directory>${project.basedir}/target/lib/</directory>
      <outputDirectory>app/lib</outputDirectory>
      <includes>
        <include>*.*</include>
      </includes>
    </fileSet>
like image 38
Uwe Andersen Avatar answered Oct 11 '22 13:10

Uwe Andersen