23

There is an existing issue for this approach, located on Codehaus JIRA #ARCHETYPE-57, but all instructions listed in this ticket failed for me. Also the blog post of marekdec How to get maven archetype to generate empty directories fails for me.

The trick within the archetype.xml with the trailing / doesnt works for me:

<resources>
  <resource>src/main/webapp/</resource>

Unable to find resource 'archetype-resources/src/main/webapp/'

Also the fileSet directory in archetype-metadata.xml does not work for me:

<fileSet filtered="true" encoding="UTF-8">
 <directory>src/main/webapp/</directory>
</fileSet>

I use the following maven-archetype-plugin to create my custom archetype.

mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-5:create

Is there any other solution? Or did i miss something? Thanks

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Christopher Klewes
  • 11,181
  • 18
  • 74
  • 102

3 Answers3

23

I did a quick test and... it worked for me. First, I created an archetype:

$ mvn archetype:generate -B -DarchetypeArtifactId=maven-archetype-archetype \
                            -DgroupId=com.stackoverflow \
                            -DartifactId=Q2786966 \
                            -Dversion=1.0-SNAPSHOT \

I renamed the archetype.xml into archetype-metadata.xml (the former is for Archetype 1.0.X, the later is for Archetype 2.0.X) so the project looks like:

$ tree .
.
├── pom.xml
└── src
    └── main
        └── resources
            ├── archetype-resources
            │   ├── pom.xml
            │   └── src
            │       ├── main
            │       │   └── java
            │       │       └── App.java
            │       └── test
            │           └── java
            │               └── AppTest.java
            └── META-INF
                └── maven
                    └── archetype-metadata.xml

And archetype-metadata.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="Q2786966">
  <fileSets>
    <fileSet filtered="true" encoding="UTF-8">
      <directory>src/main/webapp</directory>
    </fileSet>
    <fileSet filtered="true" packaged="true">
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.java</include>
      </includes>
    </fileSet>
  </fileSets>
</archetype-descriptor>

Then I installed the archetype and used it to create a project:

$ mvn install
$ cd ~/tmp
$ mvn archetype:generate -B -DarchetypeGroupId=com.stackoverflow \
                            -DarchetypeArtifactId=Q2786966 \
                            -DarchetypeVersion=1.0-SNAPSHOT \
                            -DgroupId=my.group \
                            -DartifactId=my-artifact \
                            -Dversion=1.0-SNAPSHOT

And the resulting project looks like this:

$ tree my-artifact/
my-artifact/
├── pom.xml
└── src
    └── main
        ├── java
        │   └── my-group
        │       └── App.java
        └── webapp

The empty webapp directory is there.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • Thank you Pascal, my fault was that i thought both files `archetype.xml` and `archetype-metadata.xml` are necessary, thanks for clarifying that `archetype.xml` is for older archetype-plugin versions, thats why i ran into the old mechanism. – Christopher Klewes May 10 '10 at 09:18
20

I solved this issue by adding the following configuration to the archetypes pom.xml build configuration.

Assuming your archetype-metadata.xml configuration file's filesets is as follows:

<fileSet encoding="UTF-8">
 <directory>src</directory>
  <includes>
   <include>**/**</include>
  </includes>
</fileSet>

Add this to your pom.xml, not the one included with the archetype, the actual project pom.xml

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

The xml configuration line which does the magic is

<includeEmptyDirs>true</includeEmptyDirs>

The full configuration will look as follows

<project ...>
...

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

        </plugins>
    </build>

</project>
isawk
  • 436
  • 1
  • 4
  • 10
7

I met the same problem with the first answer to this question. Reconfiguring the maven-resources-plugin.

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>
Community
  • 1
  • 1
Montells
  • 6,389
  • 4
  • 48
  • 53