Maven web 工程创建异常----Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:po

一、问题描述及解决方案

1、问题描述:Eclipse创建maven  web(选择maven-archetype-webaap)工程时,出现如下异常:

Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (C:\Users\smpatric\.m2\repository)

2、解决方案:

     

重新创建一个maven web工程,此时,会重新从远程仓库下载该文件到本地仓库,并创建maven web工程。(若是使用maven-archetype-quickstart   Archetype创建maven项目出现上述类似错误,则删掉对应的文件夹maven-archetype-quickstart即可)


3、问题分析

出现上述问题,可能是本地仓库中的maven-archetype-webapp文件夹中的文件不全,导致创建失败,出现上述错误信息。(想了解具体原因,可参考下面的叙述)



二:Archetype使用概述

1、什么是Archetype?

Archetype是一种工具包,用于创建Maven工程的模板,它可以帮助用户快速生成项目骨架。它是通过maven-archetype-plugin插件实现
一个Archetype定义了要做的相同类型事情的初始样式或模型,假如公司内的一些项目都是用同样的框架和项目结构,为一个个项目重复构建同样的配置及同样的目录结构,这是难以接受的,此时可以创建一个属于自己的Archetype项目。创建好Archetype项目后,可以打包上传到本地仓库或私服供其他人员使用

      

2、常用的Archetype

maven-archetype-quickstart:maven工程模版

maven-archetype-webapp :maven web工程模版


3、archetype-catalog.xml是什么?

archetype-catalog.xml提供了Archetype的信息(GroupId、ArtifactId、version位置信息)。

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog>
  <archetypes>
    <archetype>
      <groupId>com.github.casmi.archetypes</groupId>
      <artifactId>casmi-quickstart</artifactId>
      <version>0.3.2</version>
      <description>Quickstart archetype for casmi project</description>
    </archetype>
    <archetype>
      <groupId>com.github.choonchernlim</groupId>
      <artifactId>choonchernlim-archetype-webapp</artifactId>
      <version>0.3.0</version>
      <description>Parent POM for generating build reports for CI servers, pushing artifacts to Sonatype OSSRH and site
        documentation to GitHub</description>
    </archetype>
    <archetype>
          .........
    </archetype>
  </archetypes>
</archetype-catalog>

可以按上面的模版,编写自己的archetype-catalog.xml文件,将自己的Archetype配置到archetype-catalog.xml文件文件中。


4、archetype-catalog.xml文件的来源

archetype-catalog.xml能够提供Archetype的信息,那么maven-archetype-plugin可以从哪些位置读取archetype-catalog.xml文件呢?下面是一个列表:

  1)internal:这是maven-archetype-plugin内置的Archetype Catalog

 2)local:指向用户本地的Archetype Catalog,其位置为~/.m2/archetype-catalog.xml。(注:该文件默认不存在  )  

 3)remote:指向了Maven中央仓库的Archetype Catalog,其准确地址为http://repo1.maven.org/maven2/archetype-actalog.xml

  4)file://...:用户指定本机任何位置的archetype-catalog.xml

  5)http://...:用户可以使用http协议指定远程的archetype-catalog.xml。


5、Eclipse使用Archetype构建maven工程主要步骤如下:

     1)new----->maven  Project

     2)选择archetype-catalog.xml与Archetype



    4)填写maven项目信息















  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值