初学MAVEN之mvn archetype:generate失败

跟着网上的教程学习maven。
第一步当然是安装和环境变量配置,相信大家都没有什么问题。值得一提的是,官方所提到的配置文件settings.xml的两个目录中,*** m a v e n . h o m e / c o n f / s e t t i n g s . x m l m a v e n . h o m e {maven.home}/conf/settings.xml***的maven.home是你自己定义的环境变量目录,而*** {user.home}/.m2/settings.xml***的user.home则是你请求命令时自动生成的目录,位置是C:\Users\用户名\.m2。这个小问题我倒是还纠结了一会,索性写出来。
安装成功后需要测试是否安装成功,在cmd操作台上面输入:mvn -v。有如下界面的表示maven安装成功。
在这里插入图片描述
第二步是,选择一个目录,建立项目原型。这一步需要获得与maven中央仓库的连接,从中央仓库下载jar依赖到本地仓库。在这里我没有修改settings.xml中关于本地仓库的配置,所以默认地址是${user.home}/.m2。我选择f盘下的一个目录操作。如下
在这里插入图片描述
到这里,基本上各种教程都会要求大家在cmd中输入:mvn archetype:generate。可是问题也出现在这里,无论我怎么尝试,命令操作都是失败的。

F:\demo>mvn archetype:generate
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.4: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.4
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.3/maven-site-plugin-3.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-site-plugin:3.3: Plugin org.apache.maven.plugins:maven-site-plugin:3.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-site-plugin:jar:3.3
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:2.8: Plugin org.apache.maven.plugins:maven-dependency-plugin:2.8 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.8
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.5.3/maven-release-plugin-2.5.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.5.3: Plugin org.apache.maven.plugins:maven-release-plugin:2.5.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:jar:2.5.3
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.460 s
[INFO] Finished at: 2020-01-05T06:14:14+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'archetype' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\Judy朱\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

你可以稍微认真看下以上提示,了解失败信息。于是我开始各种网上查找解决办法,包括根据错误提示信息去查看官网文档。操作失败的另一个表现是,在我的本地仓库里下载的jar文件全是lastUpdated结尾的。如图
在这里插入图片描述
网上提示说是jar文件下载失败,重新删除后再次操作***mvn archetype:generate***即可。但是试了还是不行。
现在回想下,出错原因无非就是3种。第1种,版本问题;第2种,配置问题,更具体点应该是settings.xml配置问题;第3种,网络问题,通过网上文章得到。
第1个原因,版本问题。我下载了另一个版本的maven,重新操作,依旧失败。
在这里插入图片描述
我在第2个原因的问题上纠结了最久,包括搜博客,看文档。可是依旧没有解决。现在回想的话,其实这个原因也可以最早排除,因为搜到的好几个maven学习教程种,对于操作mvn archetype:generate这种初级的使用,都没有谈到配置问题。并且默认的配置已经能满足大多数需求,不可能在这个小白问题上设立门槛。
第3个原因,网上搜到的内容大多数是说“maven联通网络下中央仓库不能访问的解决办法”。引用博客https://blog.csdn.net/aikunjiao3421/article/details/101970902白痴的我专门测了下我自己的宽带,发现自己是电信的。
在这里插入图片描述
这就更让我迷了。并且我使用上面那位博主的解决方法也是没有解决我的问题。就这么纠结了很久,最终证明确实是网路原因。解决办法是配置阿里云仓库。
引用博客https://blog.csdn.net/qq_41829904/article/details/93843987
所以不光是联通网络,可能部分网络都会出现这样的问题。
问题解决后,项目原型构建成功,大快人心。

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-j2ee-simple:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.zyc
[INFO] Parameter: packageName, Value: com.zyc.myapp
[INFO] Parameter: package, Value: com.zyc.myapp
[INFO] Parameter: artifactId, Value: myapp
[INFO] Parameter: basedir, Value: F:\demo
[INFO] Parameter: version, Value: 1.0
[INFO] project created from Old (1.x) Archetype in dir: F:\demo\myapp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:32 min
[INFO] Finished at: 2020-01-05T07:12:57+08:00
[INFO] ------------------------------------------------------------------------
发布了13 篇原创文章 · 获赞 0 · 访问量 233

猜你喜欢

转载自blog.csdn.net/weixin_43859070/article/details/103839932