创建maven项目指定自定义-DarchetypeCatalog=file://archetype-catalog.xml遇到的问题

    在《Maven实战》第353页,书上说maven-archetype-plugin插件可以从internal、local、remote、file://...、http://...这几个地方读取archetype-catalog.xml文件。然后我也自定义了一个archetype-catalog.xml文件,放在任意一个目录下,内容为


<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <archetypes>
    <!-- 这是自己创建的maven骨架原型 -->
    <archetype>
      <groupId>com.juvenxu.mvnbook.archetypes</groupId>
      <artifactId>mvnbook-archetype-sample</artifactId>
      <version>1.0-SNAPSHOT</version>
      <description>sample</description>
    </archetype>
    <!-- 这是系统默认的maven骨架 -->
    <archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-quickstart</artifactId>
      <version>1.0</version>
      <description>quickstart</description>
    </archetype>
 </archetypes>
</archetype-catalog>

   

     以上archetype-catalog.xml文件里面就只定义了两个archetype,现在来看下效果,当我执行如下命令时:


mvn archetype:generate -DarchetypeCatalog=file://D:/maven/archetype-catalog.xml

    

     结果报错了:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project standalone-pom: archetypeCatalog 'http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/archetype-catalog.xml' is not supported anymore. Please read the plugin documentation for details. -> [Help 1]

  

   原因是:maven-archetype-plugin 3.x插件有一些有争议性的变化,带来的直接影响就是对一些参数(例如自定义archetype-catalog.xml)不再支持,有bug,这里是issues连接:

https://issues.apache.org/jira/browse/ARCHETYPE-519

http://mail-archives.apache.org/mod_mbox/maven-dev/201705.mbox/thread  (search for the thread 'The maven-archetype-plugin paradox')

  

     如果还想用自定义archetype-catalog.xml文件,就要用maven-archetype-plugin 2.x插件,改为如下:


mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=file://D:/maven/archetype-catalog.xml

  

     现在就好了,可以在交互模式中看到,让你选择从自定义的archetype-catalog.xml文件中选择一个来创建:


      参考地址:https://communities.vmware.com/message/2707795#2707795



猜你喜欢

转载自blog.csdn.net/lvyuan1234/article/details/79159115
今日推荐