How can I use the Maven Assembly Plugin to create a ZIP archive that includes a specific folder and all of its files?

331 Views Asked by At

I have a project with structure like this enter image description here

I am currently attempting to create a compressed zip folder named "wso2mi.zip" and my goal is to include all files and directories that are contained within the "wso2mi" folder. For this purpose, I have utilized the following code in pom.xml file

  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>create-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                           
                            <appendAssemblyId>false</appendAssemblyId>
                            <finalName>wso2mi</finalName>
                            <includeBaseDirectory>false</includeBaseDirectory>
                            <formats>
                                <format>zip</format>
                            </formats>
                            <fileSets>
                                <fileSet>
                                <directory>${project.basedir}/wso2mi</directory>
                                <outputDirectory>/</outputDirectory>
                                    <includes>
                                    <include>**/*</include>
                                    </includes>
                                </fileSet>
                                </fileSets>

                        </configuration>
                    </execution>
                </executions>
            </plugin>

Although I am attempting to create a zip folder named wso2mi.zip and include everything within the wso2mi folder by utilizing the code snippet mentioned above, the resulting zip folder does not contain anything apart from a few Maven files. Could you please clarify what is incorrect with the provided code?

1

There are 1 best solutions below

0
Subodh Joshi On BEST ANSWER

Solve this issue with maven assembly plugin . Created a folder assembly inside the project and under assembly folder created a zip.xml file with the following contents.

<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>zip</id>
    <includeBaseDirectory>false</includeBaseDirectory>

    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}/wso2mi</directory>
               <includes>
                     <include>**/*</include>
               </includes>
        </fileSet>
    </fileSets>
</assembly>

in pom.xml file added a plugin

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-assembly-plugin</artifactId>

        <executions>

            <execution>

                <phase>package</phase>

                <goals>

                    <goal>single</goal>

                </goals>

                <configuration>

                                <includeBaseDirectory>false</includeBaseDirectory>

                    <appendAssemblyId>false</appendAssemblyId>

                    <descriptors>

                        <descriptor>${project.basedir}/assembly/zip.xml</descriptor>

                    </descriptors>

                    <outputDirectory>${project.build.directory}/resources</outputDirectory>

                    <destFileName>${wso2esbname}-${wso2esbversion}.${wso2esbext}</destFileName>

                </configuration>

            </execution>

        </executions>

    </plugin>