使用maven命令如下,指定了archetype所在maven库地址
但还是报错,如下
命令在执行时,默认是去maven中央库中去找指定的archetype,命令行参数中的
-DarchetypeRepository
可以指定archetype所在maven库的地址,但是这个参数只在2.X中有效,3.X中是无效的.而现在大多数人下载得maven仓库都是3.X版本,导致即时使用命令
-DarchetypeRepository 指定了archetype所在maven库地址也无法拉取项目代码。
解决方法一:在maven中找到conf\settings.xml全局配置文件,配置镜像文件之后再拉取。
但是settings.xml配置文件中只允许一个有效的镜像mirror,所以使用过后建议恢复原镜像。
解决方法二:
1.在 settings.xml
的<profiles></profiles>
节点下 中增加如下配置.
<profile>
<id>profileArchetype</id>
<repositories>
<repository>
<!-- 这里的ID必须是叫 archetype -->
<id>archetype</id>
<name>私服地址 name</name>
<url>私服地址 url</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
注意:
<repository>
的id必须是叫 archetype
2.在<profiles></profiles>
之后,增加如下配置激活profile:
<activeProfiles>
<activeProfile>profileArchetype</activeProfile>
</activeProfiles>
3.(可选)如果这个私服,在下载jar包时,也需要登录认证的话,那么在<servers></servers>
节点中增加私服登录帐号信息:
<server>
<!-- 和上面的repository配置一样,这里的ID必须是叫 archetype -->
<id>archetype</id>
<username>私服登录用户名</username>
<password>私服登录密码</password>
</server>