有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Maven如何包含空目录

默认情况下,在构建过程中,maven会删除空目录
您知道是否可以在pom中指定一个参数来指示maven在生成的目标/测试类文件夹中包含空目录吗


共 (5) 个答案

  1. # 1 楼答案

    如果它不适合你,你可以使用Maven Resources Plugin 2.7

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <includeEmptyDirs>true</includeEmptyDirs>
                </configuration>
            </plugin>
    
  2. # 2 楼答案

    根据this ticket MRESOURCES-36,应该有一个<includeEmptyDirs>元素,但只适用于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版本:

    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.

    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项目中的openejb-standalone ^{}

  3. # 3 楼答案

    我使用了khmarbaise建议的汇编插件,但为了让它正常工作,我需要使用Ant风格的exclude,以确保没有文件或目录潜入存档:

    <excludes>
        <exclude>**/*</exclude>
    </excludes>
    
  4. # 4 楼答案

    我们通常通过在任何需要创建但在构建时没有有用内容的目录中包含一个空占位符文件来解决这个问题

    这还有一个优点,即不允许空目录概念的文件格式(例如zip文件)仍然可以创建正确的目录结构

  5. # 5 楼答案

    为什么在目标/测试类下需要空文件夹

    另一方面,您可以使用assembly插件在zip/tar中创建空文件夹。gz文件

    只需在程序集描述符中创建一个引用现有文件夹的条目(在本例中是src/main/resources/bin

    <fileSet>
      <directory>src/main/resources/bin</directory>
      <outputDirectory>/logs</outputDirectory>
      <directoryMode>0755</directoryMode>
      <excludes>
        <exclude>*</exclude>
      </excludes>
    </fileSet>
    

    以上内容适用于。焦油gz和zip文件。只有在创建时才需要上面的directoryMode。焦油gz文件

    第二种可能性是在文件夹结构中创建一个空文件夹,该文件夹包含在汇编插件中(如zip、tar.gz等)。。。顺便说一句:拉链,焦油。gz允许空文件夹