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?

- 5,442
- 11
- 47
- 59
5 Answers
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>
For Maven versions which included an older version of the Resources plugin:
Until this issue is fixed, here is a workaround I've been using successfully.
Add this plugin element intoproject/build/plugins
in yourpom.xml
, and change the dir in the mkdir task.You can have multiple
<mkdir>
elements for multiple directories. Themkdir
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>
This originally came from the openejb-standalone pom.xml
in the openejb project.

- 15,821
- 6
- 77
- 100

- 1,262,500
- 529
- 4,410
- 5,250
-
1Nice (and you have my +1) but I forgot to leave a comment: maybe clarify that 2.3 is the version of the Resources plugin, not Maven itself (and the antrun workaround was useful before the release of the version 2.3 of the Resource plugin) – Pascal Thivent Apr 09 '10 at 12:56
-
@Pascal: right you are, and I have updated my answer to better reflect your remarks. – VonC Apr 09 '10 at 14:41
-
I've tried this for an empty folder in `scr\main\webapp\` and it is not working with plugin version 2.6 (using first approach above). Should it? – Bizmarck Dec 02 '13 at 15:58
-
@bizmark 3 years later, I wouldn't know. That would be a good question in its own. – VonC Dec 02 '13 at 15:59
-
Nevermind, it won't work for empty folders in `scr\main\webapp\`. See https://jira.codehaus.org/browse/MWAR-128 for solution / workaround – Bizmarck Dec 02 '13 at 16:07
-
maven-resources-plugin does not create empty directories for me – user2668735 Apr 09 '19 at 09:58
Why do you need empty folders under target/test-classes?
On the other hand you can use the assembly plugin to create empty folders in zip/tar.gz files.
Just create an entry in your assembly descriptor which references an existing folder (in this case src/main/resources/bin...
<fileSet>
<directory>src/main/resources/bin</directory>
<outputDirectory>/logs</outputDirectory>
<directoryMode>0755</directoryMode>
<excludes>
<exclude>*</exclude>
</excludes>
</fileSet>
The above works for .tar.gz and zip files as well. The directoryMode above is only needed if you create .tar.gz files.
The second possibility is to create an empty folder in your folder structure which is included with the assembly plugin (like zip, tar.gz etc.)...BTW: zip, tar.gz allow empty folders.

- 15,821
- 6
- 77
- 100

- 92,914
- 28
- 189
- 235
-
6you get my +1 because I needed this assembly-trick, but why do you question the OP's needs? – Superole Apr 10 '12 at 09:51
If it's not working for you can use 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>

- 451
- 5
- 11
We've usually got around this problem by including an empty placeholder file in any directories that we need to create but which have no useful content at build time.
This also has the advantage that file formats (e.g. zip files) which don't allow the concept of empty directories will still create the right directory structure.

- 42,159
- 20
- 102
- 127
I used the Assembly Plugin like khmarbaise suggested, but to get it to work I needed to use an Ant-style exclude to make sure that no files or directories crept into the archive:
<excludes>
<exclude>**/*</exclude>
</excludes>

- 1,013
- 11
- 9