Maven - 如何包括空目录 [英] Maven - how to include empty directories

查看:384
本文介绍了Maven - 如何包括空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,在构建过程中,maven正在删除空目录。

您是否知道是否可以在pom中指定参数来指示maven在生成的目标/测试类中包含空目录文件夹?

By default during the build process maven is removing the empty directories.
Do you know if a parameter can be specified in the pom to instruct maven to include empty directories in the generated target/test-classes folder?

推荐答案

根据这张票MRESOURCES-36 ,应该有一个< includeEmptyDirs> 元素,但只适用于 Maven资源插件2.3

According to this ticket MRESOURCES-36, there should be a <includeEmptyDirs> element, but only for Maven Resources Plugin 2.3.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <includeEmptyDirs>true</includeEmptyDirs>
  </configuration>
</plugin>






对于包含较旧版本的Maven版本资源插件:


For Maven versions which included an older version of the Resources plugin:


在此问题解决之前,这是一个成功使用的解决方法。

添加这个插件元素在您的 pom.xml 中的 project / build / plugins 中,并更改mkdir任务中的目录。

Until this issue is fixed, here is a workaround I've been using successfully.
Add this plugin element into project/build/plugins in your pom.xml, and change the dir in the mkdir task.

您可以为多个目录拥有多个< mkdir> 元素。如果目录已被资源插件复制,则 mkdir 任务不起作用。

You can have multiple <mkdir> elements for multiple directories. The mkdir task does nothing if the directory has already been copied by the resources plugin.



<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>create-empty-directory</id>
      <phase>process-classes</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
          <mkdir dir="${basedir}/target/classes/empty" />
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>

这最初来自 openejb-standalone pom.xml 在openejb项目中。

This originally came from the openejb-standalone pom.xml in the openejb project.

这篇关于Maven - 如何包括空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆