Can I create empty directories while packaging using maven-assembly-plugin?

岁酱吖の 提交于 2019-12-12 11:12:37

问题


I want to create empty directory structure while doing the packaging using maven-assembly-plugin. I am successful in including all the files, but not creating the empty ones,

opt/SP/myprod/bin/*  (contains files)
opt/SP/myprod/lib/*  (contains files)
opt/SP/myprod/conf/* (contains files)
var/SP/myprod/run    (Empty directories)
var/SP/myprod/log    (Empty directories)
var/SP/myprod/tmp    (Empty directories)

The below one is my assembly file,

<id>stage</id>
<formats>
    <format>tar.gz</format>
    <format>zip</format>
</formats>

<fileSets filtered="true" encoding="UTF-8">

    <fileSet>
        <directory>${run.dir}</directory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${tmp.dir}</directory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${log.dir}</directory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${basedir}/config</directory>
        <outputDirectory>${install.dir}/config</outputDirectory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${basedir}/bin</directory>
        <outputDirectory>${install.dir}/bin</outputDirectory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${basedir}/images</directory>
        <outputDirectory>${install.dir}/images</outputDirectory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${basedir}/package-scripts</directory>
        <outputDirectory>${install.dir}/package-scripts</outputDirectory>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory>${install.dir}/lib</outputDirectory>
        <includes>
            <include>myfile.jar</include>
        </includes>
        <fileMode>755</fileMode>
    </fileSet>

    <fileSet>
        <directory>${project.build.directory}/lib</directory>
        <outputDirectory>${install.dir}/lib</outputDirectory>
        <fileMode>755</fileMode>
    </fileSet>

</fileSets>

So, I tried the simple "directory" tag as recommended in one of the blog, but no luck.

Could any one help me please?


回答1:


Note that @khmarbaise's answer will not exclude all subfolders, you need to use a stronger wildcard:

<fileSets>
    <fileSet> <!-- Create empty directory -->
        <outputDirectory>coredumps</outputDirectory>
        <excludes><exclude>**/*</exclude></excludes>
    </fileSet>
</fileSets>

Found at How do I include an empty directory in a maven assembly?




回答2:


You can use a thing like this here:

<fileSets>
  <fileSet>
     <outputDirectory>/an-other-empty-folder</outputDirectory>
     <directory>${project.basedir}/target</directory>
     <excludes>
       <exclude>*</exclude>
     </excludes>
  </fileSet>
</fileSets>


来源:https://stackoverflow.com/questions/24909699/can-i-create-empty-directories-while-packaging-using-maven-assembly-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!