如何使用maven原型创建空文件夹?

Chr*_*wes 17 maven-2 maven-archetype

这种方法存在一个问题,位于Codehaus JIRA#ARCHETYPE-57上,但此票证中列出的所有说明均未通过.marekdec的博客文章如何让maven原型生成空目录失败了.

archetype.xml尾随的诀窍/对我不起作用:

<resources>
  <resource>src/main/webapp/</resource>
Run Code Online (Sandbox Code Playgroud)

Unable to find resource 'archetype-resources/src/main/webapp/'
Run Code Online (Sandbox Code Playgroud)

fileSet目录archetype-metadata.xml也不适合我:

<fileSet filtered="true" encoding="UTF-8">
 <directory>src/main/webapp/</directory>
</fileSet>
Run Code Online (Sandbox Code Playgroud)

我使用以下maven-archetype-plugin来创建我的自定义原型.

mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-5:create
Run Code Online (Sandbox Code Playgroud)

还有其他解决方案吗?还是我错过了什么?谢谢

Pas*_*ent 21

我做了一个快速测试......它对我有用.首先,我创建了一个原型:

$ mvn archetype:generate -B -DarchetypeArtifactId=maven-archetype-archetype \
                            -DgroupId=com.stackoverflow \
                            -DartifactId=Q2786966 \
                            -Dversion=1.0-SNAPSHOT \
Run Code Online (Sandbox Code Playgroud)

我重命名为archetype.xmlinto archetype-metadata.xml(前者是Archetype 1.0.X,后者是Archetype 2.0.X)所以项目看起来像:

$ 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

archetype-metadata.xml包含:

<?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>
Run Code Online (Sandbox Code Playgroud)

然后我安装了原型并用它来创建一个项目:

$ 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
Run Code Online (Sandbox Code Playgroud)

结果项目如下所示:

$ tree my-artifact/
my-artifact/
??? pom.xml
??? src
    ??? main
        ??? java
        ?   ??? my-group
        ?       ??? App.java
        ??? webapp

空的webapp目录就在那里.


isa*_*awk 12

我通过将以下配置添加到archetypes pom.xml构建配置来解决了这个问题.

假设您的archetype-metadata.xml配置文件的文件集如下:

<fileSet encoding="UTF-8">
 <directory>src</directory>
  <includes>
   <include>**/**</include>
  </includes>
</fileSet>
Run Code Online (Sandbox Code Playgroud)

将其添加到您的pom.xml中,而不是原型中包含的实际项目pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <includeEmptyDirs>true</includeEmptyDirs>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

执行魔术的xml配置行是

<includeEmptyDirs>true</includeEmptyDirs>
Run Code Online (Sandbox Code Playgroud)

完整配置如下所示

<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>
Run Code Online (Sandbox Code Playgroud)


mon*_*lls 5

我对这个问题的第一个答案遇到了同样的问题.重新配置maven-resources-plugin.

根据这张票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>
Run Code Online (Sandbox Code Playgroud)