当前位置: 首页 > 知识库问答 >
问题:

自定义maven原型不生成在archtype.xml中定义的源

景宏盛
2023-03-14

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

在使用这个原型生成项目时,没有包含我在archetype.xml中定义的任何源(pom.xml按预期生成)。

<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>

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

我还有一个原型-metadata.xml位于src/main/resources/meta-inf/maven中,用来定义依赖版本

<?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>
[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] ------------------------------------------------------------------------   
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] ------------------------------------------------------------------------

当从这个原型生成一个项目时,我需要做什么来包含这些文件?

共有1个答案

师野
2023-03-14

archetype-metadata.xml是一个archetype2.x描述符,而archetype.xml是一个archetype1.x描述符。同时使用这两种方法意味着忽略archetype.xml中的任何内容。包括archetype-metadata.xml中的文件生成和删除archetype.xml修复了该问题。

 类似资料:
  • Maven告诉我:您的过滤器与任何原型都不匹配。我的系统: null 我已采取的步骤是: Create my project Navigate to my project in command prompt and run the command: cd返回到“我的项目”文件夹并运行命令 运行该命令后,我会看到:

  • 更新(阅读后传递额外的属性到maven原型:生成): 我创造了自己的原型。src/main/资源/原型资源/pom.xml: 想要使用我自己的第三方deps工件和第三方deps版本参数。所以我添加了src/main/resources/META-INF/maven/archetype元数据。xml文件: 将archetype安装到我的本地存储库中。然后根据我的自定义原型创建工件: mvn原型:生成

  • 问题内容: 我想在Eclipse中生成自定义方法,就像我们可以生成toString,getter和沉降器的方式一样(右键单击-> source->)。谁能告诉我这样做涉及什么? 谢谢, 荷兰人 问题答案: 您可以在最近(Eclipse Galileo 3.5)生成动作之后添加自己的动作, 使用主动贡献URI: 具有活动操作定义标识符: 使用有效贡献项目类:(包) 来自贡献插件:org.eclips

  • 问题内容: 以下两个JavaScript原型之间的功能区别是什么?选择一个与另一个原型有什么好处? 选项1: 选项2: 我是否假设 选项2 导致废弃某些隐式绑定到原型的函数是否正确? 问题答案: 我是否假设选项2导致废弃某些隐式绑定到原型的函数是否正确? 对,就是这样。尽管唯一隐式绑定的属性是您很少需要的属性。 功能上有什么区别? 选项1只是扩展现有的原型。如果已经有从原型对象继承的实例,则它们也

  • 是否有方法重写build方法返回SampleClass以避免执行build.build?

  • 有没有办法为自定义生成的代码? 考虑以下简单类: 我希望Lombok为生成Setter,就像我在上面的示例中实现的那样。这应该只在用注释的类和作为的属性上完成。其他属性的Setter,在本例中应该像往常一样生成。 是否有办法根据这些标准定制Setter代码的生成?