cenos7下maven安装及使用

目录

1.下载

2.安装

3.检查是否安装成功

4.问题

1.报错提示Could not transfer artifact

2.报错冲突

3.下载文件速度慢

5.仓库配置

1.私服配置

2.非私服仓库配置


1.下载

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

2.安装

yum install apache-maven -y

3.检查是否安装成功

mvn -v

4.问题

1.报错提示Could not transfer artifact

原因是部署maven的机器是通过代理上网的,所有maven需要设置代理

mvn -v
vim settings.xml

<proxy>
   <id>optional</id>
   <active>true</active>
   <protocol>http</protocol>
   <username>root</username>
   <password>password</password>
   <host>ip</host>
   <port>3128</port>
   <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>

2.报错冲突

Transaction check error:
  file /usr/share/java/plexus/plexus-cipher.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package plexus-cipher-1.7-5.el7.noarch
  file /usr/share/java/plexus/plexus-sec-dispatcher.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package plexus-sec-dispatcher-1.4-13.el7.noarch
  file /usr/share/java/maven-wagon/file.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package maven-wagon-0:2.4-3.el7.noarch
  file /usr/share/java/maven-wagon/provider-api.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package maven-wagon-0:2.4-3.el7.noarch

Error Summary

解决:

依次删除冲突的包,如果提示有依赖导致删除不了,则先删除依赖的包

rpm -e plexus-cipher-1.7-5.el7.noarch
rpm -e aether-connector-wagon-1.13.1-13.el7.noarch
rpm -e maven-wagon-0:2.4-3.el7.noarch

3.下载文件速度慢

mvn -v
vim settings.xml

    <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>        
    </mirror>

5.仓库配置

1.私服配置

查找安装位置

whereis maven

修改配置settings.xml

#设置本地仓库地址
<localRepository>/usr/local/repo</localRepository>
#设置私服访问帐号密码
   	<server>
		<id>maven-public</id>
		<username>admin</username>
		<password>admin</password>
	</server>
#仓库地址
<profiles>
    <profile>
                <id>nexus</id>
                <repositories>
                        <repository>
                                <id>nexus</id>
                                <name>nexus</name>
                                <url>http://ip:port/nexus/repository/maven-public/</url>
                                <release>
                                        <enabled>true</enabled>
                                </release>
                                <snapshots>
                                        <enabled>true</enabled>
                                </snapshots>
                        </repository>
                </repositories>
                <pluginRepositories>
                        <pluginRepository>
                                <id>nexus</id>
                                <name>nexus</name>
                                <url>http://ip:port/nexus/repository/public/</url>
                                <release>
                                        <enabled>true</enabled>
                                </release>
                                <snapshots>
                                        <enabled>true</enabled>
                                </snapshots>
                        </pluginRepository>
                </pluginRepositories>
        </profile>
  
</profiles>
#激活配置
  <activeProfiles>
	<activeProfile>nexus</activeProfile>
  </activeProfiles>

2.非私服仓库配置

当maven依赖的jar包不在本地仓库时,会先从mirror里面去找,找不到再去repo里面去找,mirror相当于拦截请求,改变仓库请求地址。

<mirrors>   
<mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

<!-- 中央仓库1 -->
<mirror>
    <id>repo1</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo1.maven.org/maven2/</url>
</mirror>

<!-- 中央仓库2 -->
<mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url>
</mirror>
  </mirrors>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值