Maven原型(prototype)生成不包括来自原型(prototype)资源的文件

2020年12月2日 102点热度 0条评论

我正在创建一个maven archetype,但是当我生成具有此原型的项目时,源为空。

缺少什么吗?

有没有简单的原型开始?我尝试了maven-archetypes,但是每个项目都从父项目artifactId maven-archetype-bundles继承。

Maven原型

base-archetype
  -src
    -main
      -java
      -resources
        -archetype-resources
          -resources
            -META-INF
              messages.properties
          -webapp
            -WEB-INF
              beans.xml
          pom.xml(b)
        -META-INF
          -maven
            archetype-metadata.xml
    -test
  -target
  pom.xml(a)

pom.xml(a)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.javalabs</groupId>
    <artifactId>simple-archetype</artifactId>
    <version>0.0.1</version>
    <packaging>maven-archetype</packaging>
...    

    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.archetype</groupId>
                <artifactId>archetype-packaging</artifactId>
                <version>3.1.2</version>
            </extension>
        </extensions>

        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-archetype-plugin</artifactId>
                    <version>3.0.1</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </build>
    ...
</project>

archetype-metadata.xml

<archetype-descriptor
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
        http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
        xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        name="jakartaee-essentials-archetype">

    <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.java</include>
            </includes>
        </fileSet>

        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </fileSet>

        <fileSet filtered="true" packaged="false" encoding="UTF-8">
            <directory>src/main/webapp</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </fileSet>

        <fileSet>
            <directory>src/test/java</directory>
        </fileSet>

        <fileSet filtered="false" packaged="false" encoding="UTF-8">
            <directory></directory>
            <includes>
                <include>.gitignore</include>
            </includes>
        </fileSet>
    </fileSets>

</archetype-descriptor>

解决方案如下:

原型的结构存在一些错误,在archetype-resources文件夹中缺少src和主要级别。

base-archetype
  -src
    -main
      -java
      -resources
        -archetype-resources
          -**src**
            -**main**
              -resources
                -META-INF
                  messages.properties
                -webapp
                  -WEB-INF
                    beans.xml
            pom.xml(b)
        -META-INF
          -maven
            archetype-metadata.xml
    -test
  -target
  pom.xml(a)