-3

enter image description hereCan any one help me with this. Using maven , I need to create zip file with of a directory , which is inside the project.

Any example will help.

Aravind
  • 93
  • 1
  • 3
  • 8

1 Answers1

2

The maven assembly plugin can create a zip file of anything you want. The documentation is pretty good, you can see an example here.

The gist of it is adding an xml file that describes how files are to be assembled, and then reference that from pom.xml. Here's an example of the assembly descriptor (taken from the website):

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
  <id>distribution</id>
  <formats>
    <format>zip</format>
  </formats>
  <files>
    <file>
      <source>README.txt</source>
      <outputDirectory></outputDirectory>
      <filtered>true</filtered>
    </file>
    <file>
      <source>LICENSE.txt</source>
      <outputDirectory></outputDirectory>
    </file>
    <file>
      <source>NOTICE.txt</source>
      <outputDirectory></outputDirectory>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>

And then in pom.xml you'd reference this file like so (assuming the file is called distribution.xml under the assembly directory):

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/distribution.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
   [...]
</project>

There's a bunch more options to help you filter out files or include/exclude directories and so on. All in the docs.

Kraylog
  • 7,383
  • 1
  • 24
  • 35
  • org.apache.maven.plugins maven-assembly-plugin 3.0.0 \src\main\assembly\bin.xml create-zipfile install single – Aravind Jul 11 '17 at 19:54
  • 1
    Would be easier to help you if you add that to a snippet in your original post. – Kraylog Jul 11 '17 at 19:59
  • i added snipped in original post – Aravind Jul 11 '17 at 20:09
  • Your bin.xml is apparently missning an `` tag. See the error message at the bottom of the image you posted. – Kraylog Jul 12 '17 at 15:06
  • I never thought that it was going in bin.xml, i was thiking in parent pom it was complaining. Thanks for catching. this Issue is resolved.Thankyou very much for your help. – Aravind Jul 13 '17 at 14:51
  • You're very welcome. Please mark the answer as accepted, so avoid other people trying to answer this question. – Kraylog Jul 13 '17 at 15:40
  • https://stackoverflow.com/questions/45087114/how-can-we-zip-two-separate-directories-in-seperate-zip-files-using-assembly-pli have posted another question can you help? related one. – Aravind Jul 13 '17 at 17:21
  • The provided link is now outdated (13 jun 2022), @Kraylog can you include a digest of the plugin usage in your answer ? – Zilog80 Jun 13 '22 at 08:50
  • 1
    @Zilog80 there ya go. – Kraylog Jun 14 '22 at 14:19