13

I followed the answer for how to create a ZIP archive in Maven here: https://stackoverflow.com/a/2514677/1395165 and have a couple of follow-up questions:

ZIP contents to exclude directory:

As in the example I have:

<fileSet>
    <directory>${project.basedir}/src/export</directory>
    <useDefaultExcludes>true</useDefaultExcludes>
</fileSet>

In the ZIP I get

src
  export
     Dir1
     Dir2

but I only want to have

Dir1
Dir2 

in the ZIP. Is that possible?

Output file name

The output file name is created with a .zip extension. Is it possible in Maven to override the extension to something else (say .abc)?

Community
  • 1
  • 1
sedge
  • 385
  • 1
  • 4
  • 15

3 Answers3

17

The outputDirectory option can be used to change the directory within the assembly that the files are output to - this should do what you need:

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
    <format>zip</format>
</formats>
<fileSets>
    <fileSet>
        <directory>${project.basedir}/ScriptedBuild/rConnect/extract/</directory>
        <useDefaultExcludes>true</useDefaultExcludes>
        <outputDirectory>/</outputDirectory>
    </fileSet>
</fileSets>
</assembly> 
Ray M
  • 329
  • 1
  • 4
  • You definitely pointed me in the right direction. However I had to do this `..` to achieve what was asked. Did I miss something? – mks-d Jul 12 '17 at 19:53
  • 1
    If you don't set `baseDirectory` then it defaults to `${project.build.finalName}` like `App-0.0.3-SNAPSHOT/` inside the zip file. – Chloe Nov 15 '18 at 00:43
1

set includeBaseDirectory to false - see http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • Thanks for the response. I had tried that and a lot of variations of baseDirectory. I've posted my zip.xml as an answer because it didn't seem to want to post in the comment area. – sedge May 15 '12 at 22:40
1

Use

<assembly ...
  <baseDirectory>/</baseDirectory>

And

<fileSet>
  <outputDirectory>/</outputDirectory>

That will put all files in the root of the zip file.

BaseDirectory sets the directory inside the zip to use for all files, like it prepends it to all paths. That way when you upzip it without making a directory first, it doesn't pollute your current working directory.

OutputDirectory sets the directory inside the zip file. BaseDirectory is still 'prepended' to this. So BaseDirectory = /project-1.2.3 and OutputDirectory /src will create project-1.2.3/src/ inside the zip.

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

baseDirectory String Sets the base directory of the resulting assembly archive. If this is not set and includeBaseDirectory == true, ${project.build.finalName} will be used instead. (Since 2.2-beta-1)

outputDirectory String Sets the output directory relative to the root of the root directory of the assembly. For example, "log" will put the specified files in the log directory.

Community
  • 1
  • 1
Chloe
  • 25,162
  • 40
  • 190
  • 357