java - 自定义 Maven 原型(prototype)不会生成 archtype.xml 中定义的源

标签 java maven maven-archetype

我正在尝试创建一个自定义原型(prototype),它定义了一个实质性的 pom.xml 并包含几个源文件。

使用此原型(prototype)生成项目时,我在 archetype.xml 中定义的任何源都不包含在内(pom.xml 按预期生成)。

我的 archetype.xml 位于 src/main/resources/META-INF/maven 并定义了两个源。

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

<sources>       
    <source>src/main/java/App.java</source>
</sources>
<resources>
    <resource>src/test/java/BatFile.bat</resource>
</resources>
</archetype>

App.java 位于 src/main/resources/archetype-resources/src/main/java 中。

BatFile.bat 位于 src/main/resources/archetype-resources/src/main/resources 中。

我还有一个位于 src/main/resources/META-INF/maven 的 archetype-metadata.xml,我用它来定义依赖版本

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="custom">
    <requiredProperties>
        <requiredProperty key="thorntail-version">
            <defaultValue>2.2.1.Final</defaultValue>
        </requiredProperty>
    </requiredProperties>
</archetype-descriptor>

我的根pom.xml如下

<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>uk.co.xxxxx</groupId>
<artifactId>custom-archetype</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Custom Archetype</name>
<description>Archetype for Custom projects</description>
</project>

我正在关注专家 Documentation关于创建自定义原型(prototype),据我所知,我做的一切都是正确的。

这是运行 mvn install 的结果

[INFO] Scanning for projects...                                                   
[INFO]                                                                            
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreade
d.SingleThreadedBuilder with a thread count of 1                                  
[INFO]                                                                            
[INFO] ------------------------------------------------------------------------   
[INFO] Building Custom Archetype 0.0.1-SNAPSHOT                                  
[INFO] ------------------------------------------------------------------------   
[INFO]                                                                            
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ custom-archetype ---                                                                         
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                   
[INFO] Copying 6 resources                                                        
[INFO]                                                                            
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ custom-archetype ---                                                                            
[INFO] Nothing to compile - all classes are up to date                            
[INFO]                                                                            
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ custom-archetype ---                                                                 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                   
[INFO] Copying 0 resource                                                         
[INFO]                                                                            
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile)  custom-archetype ---
[INFO] No sources to compile   
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ custom-archetype 
---                                                                              
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ custom-archetype ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ custom-archetype        
 ---
[INFO] Installing D:\dev\customarchetype\target\custom-archetype-0.0.1-SNAPSHOT.jar to C:\Users\xxxx\.m2\repository\uk\co\xxxxx\custom-archetype\0
.0.1-SNAPSHOT\custom-archetype-0.0.1-SNAPSHOT.jar                                
[INFO] Installing D:\dev\custom\customarchetype\pom.xml to C:\Users\xxxx\.m2\rep
ository\uk\co\xxxxx\custom-archetype\0.0.2-SNAPSHOT\custom-archetype-0.0.
1-SNAPSHOT.pom                                                                    
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS                                                              
[INFO] ------------------------------------------------------------------------   
[INFO] Total time: 2.849 s                                                        
[INFO] Finished at: 2019-01-11T09:29:18+00:00                                     
[INFO] Final Memory: 8M/245M                                                      
[INFO] ------------------------------------------------------------------------   

我正在运行以下 Maven 命令来生成我的项目

mvn archetype:generate -DarchetypeGroupId=uk.co.gamma.xxxxx -DarchetypeArtifactId=custom-archetype -DarchetypeVersion=0.0.1-SNAPSHOT -DgroupId=uk.co.xxxxx -Dversion=0.0.1-SNAPSHOT -DartifactId=test12 -Dpackage=uk.co.xxxxx

这是输出

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [uk.co.xxxxx:custom-archetype:0.0.1-SNAPSHOT] found in catalog local
[INFO] Using property: groupId = uk.co.xxxxx
[INFO] Using property: artifactId = test12
[INFO] Using property: version = 0.0.1-SNAPSHOT
[INFO] Using property: package = uk.co.xxxxx
[INFO] Using property: thorntail-version = 2.2.1.Final
Confirm properties configuration:
groupId: uk.co.xxxxx
artifactId: test12
version: 0.0.1-SNAPSHOT
package: uk.co.xxxxx
thorntail-version: 2.2.1.Final
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: custom-archetype:0.0.1-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: uk.co.xxxxx
[INFO] Parameter: artifactId, Value: test12
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: package, Value: uk.co.xxxxx
[INFO] Parameter: packageInPathFormat, Value: uk/co/xxxxx
[INFO] Parameter: package, Value: uk.co.xxxxx
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: thorntail-version, Value: 2.2.1.Final
[INFO] Parameter: groupId, Value: uk.co.xxxxx
[INFO] Parameter: artifactId, Value: test12
[INFO] Project created from Archetype in dir: D:\dev\testarchetype\test12
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.281 s
[INFO] Finished at: 2019-01-11T10:27:45+00:00
[INFO] Final Memory: 13M/183M
[INFO] ------------------------------------------------------------------------

生成的项目仅包含pom.xml。

从该原型(prototype)生成项目时,我需要做什么才能包含这些文件?

最佳答案

archetype-metadata.xml 是 archetype 2.x 描述符,而 archetype.xml 是 archetype 1.x 描述符。使用两者意味着 archetype.xml 中的任何内容都将被忽略。在 archetype-metadata.xml 中包含文件生成并删除 archetype.xml 可以解决该问题。

关于java - 自定义 Maven 原型(prototype)不会生成 archtype.xml 中定义的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54133632/

相关文章:

Liferay 钩子(Hook)的 Maven 原型(prototype)

java - 用于简单 Servlet 应用程序的 Maven 原型(prototype)

java - 如何格式化java日期

java - 将多个git存储库导入Intellij中的一个项目

java - 导入扫描仪时必须声明一个命名包

maven - JUnit + Maven +并行测试执行错误

java - 在 Karaf 中启动 bundle 时出现 OSGi os.wiring.package 错误

java - 是否可以执行 Java 代码作为从 Maven 原型(prototype)生成项目的一部分?

java - 尝试将 TomEE 1.7.2 与嵌入式 Tomcat 集成时,ejb-example 无法正常工作

java - for循环中的迭代是什么意思?