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

孤者浪人 提交于 2019-11-29 11:11:08

问题


In what must be a common occurence, I need to include an empty directory in an assembly. In my case it is logs/.

I've tried different variations in the assembly descriptor like:

<fileSet>
  <directory>${basedir}/target</directory>
  <includes>
    <include>doesntexist</include>
  </includes>
  <outputDirectory>/logs</outputDirectory>
  <fileMode>0644</fileMode>
</fileSet>

and the directory just gets pruned.

I tried to exclude as well, but that still included lots of stuff:

<fileSet>
  <directory>${basedir}/target</directory>
  <excludes>
    <exclude>*</exclude>
  </excludes>
  <outputDirectory>/logs</outputDirectory>
  <fileMode>0644</fileMode>
</fileSet>

回答1:


This always works for me:

<fileSets>
  <fileSet>
    <directory>.</directory>
    <outputDirectory>logs</outputDirectory>
    <excludes>
      <exclude>*/**</exclude>
    </excludes>
  </fileSet>
</fileSets>



回答2:


Courtesy, this SO answer and with some trial and error, the following one seems to work for me...

<fileSet>
  <directory>src/main/assembly</directory>
  <outputDirectory>/logs</outputDirectory>
  <excludes>
    <exclude>*</exclude>
  </excludes>
</fileSet>

The key seems to be to ensure that <directory> tag specifies a valid/existing folder, which does not have any subfolders.




回答3:


<fileSets>
    <fileSet>
        <directory>./EMPTY_DIRECTORY_NAME</directory>
        <outputDirectory>/REQUIRED_DIRECTORY_NAME in Assembly </outputDirectory>
        <excludes>
            <exclude>*/**</exclude>
        </excludes>
    </fileSet>
</fileSets>

e.g.

<fileSets>
    <fileSet>
        <directory>./Logs</directory>
        <outputDirectory>/Feed</outputDirectory>
        <excludes>
          <exclude>*/**</exclude>
        </excludes>
    </fileSet>
</fileSets>

In this case even though there are some content inside Logs directory, it will not be included in assembled binary in Feed directory.



来源:https://stackoverflow.com/questions/7909183/how-do-i-include-an-empty-directory-in-a-maven-assembly

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