Create a ZIP archive with Maven












9















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)?










share|improve this question





























    9















    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)?










    share|improve this question



























      9












      9








      9


      0






      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)?










      share|improve this question
















      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)?







      maven-2 zip






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 '17 at 12:10









      Community

      11




      11










      asked May 15 '12 at 4:49









      sedgesedge

      1851310




      1851310
























          3 Answers
          3






          active

          oldest

          votes


















          14














          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>





          share|improve this answer
























          • You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

            – mks-d
            Jul 12 '17 at 19:53











          • 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 0:43



















          1














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






          share|improve this answer
























          • 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



















          0














          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.







          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10594291%2fcreate-a-zip-archive-with-maven%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            14














            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>





            share|improve this answer
























            • You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

              – mks-d
              Jul 12 '17 at 19:53











            • 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 0:43
















            14














            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>





            share|improve this answer
























            • You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

              – mks-d
              Jul 12 '17 at 19:53











            • 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 0:43














            14












            14








            14







            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>





            share|improve this answer













            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>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 6 '12 at 1:37









            Ray MRay M

            29914




            29914













            • You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

              – mks-d
              Jul 12 '17 at 19:53











            • 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 0:43



















            • You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

              – mks-d
              Jul 12 '17 at 19:53











            • 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 0:43

















            You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

            – mks-d
            Jul 12 '17 at 19:53





            You definitely pointed me in the right direction. However I had to do this <outputDirectory>..</outputDirectory> to achieve what was asked. Did I miss something?

            – mks-d
            Jul 12 '17 at 19:53













            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 0:43





            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 0:43













            1














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






            share|improve this answer
























            • 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














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






            share|improve this answer
























            • 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












            1








            1







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






            share|improve this answer













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







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 15 '12 at 5:14









            GreyBeardedGeekGreyBeardedGeek

            21.1k12847




            21.1k12847













            • 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



















            • 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

















            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





            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











            0














            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.







            share|improve this answer




























              0














              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.







              share|improve this answer


























                0












                0








                0







                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.







                share|improve this answer













                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.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 0:40









                ChloeChloe

                10.9k1979193




                10.9k1979193






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10594291%2fcreate-a-zip-archive-with-maven%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values