JAVA Maven和ANT 安装 Linux(Ubuntu/Centos),Mac

JDK安装

http://blog.csdn.net/fenglailea/article/details/26006647
环境变量设置
http://blog.csdn.net/fenglailea/article/details/52457731
风.fox

YUM 临时代理

命令行中先执行如下命令,然后再执行yum xxx命令

export http_proxy="http://10.1.5.50:9999"

http://10.1.5.50:9999 :代理服务器IP和端口

Maven

Apache Maven是一个软件项目管理和综合工具。基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报告和文件。
本教程将介绍如何使用Maven在Java开发,或任何其他的编程语言的任何项目。
http://www.yiibai.com/maven/

Maven 安装

编译后代码安装

下载地址:http://maven.apache.org/download.cgi
选择 Binary tar.gz archive

wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
tar zxvf apache-maven-3.6.1-bin.tar.gz
mkdir -p /usr/java/
mv apache-maven-3.6.1 /usr/java/

设置环境变量文件

vim /etc/profile.d/maven.sh

设置环境变量

#!/bin/bash
export MAVEN_HOME=/usr/java/apache-maven-3.6.1
export M2_HOME=$MAVEN_HOME
export PATH=$MAVEN_HOME/bin:$PATH

应用生效

source /etc/profile
source /etc/bashrc

yum repo安装

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

yum -y install apache-maven

如果手动安装过JAVA ,使用下面更新Maven 中的JAVA版本

alternatives --config java
alternatives --config javac

maven的java文件编译后会保存在target目录下

查看Maven版本

mvn -v

Maven 更改国内镜像设置【推荐】

找到 maven目录

vim /usr/java/apache-maven-3.5.4/conf/settings.xml

找到mirrors,修改或增加如下

 <mirrors>
    <mirror>
      <id>ali maven</id>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>

这个时候就可以享受飞速下载了
来自
http://blog.csdn.net/u010717403/article/details/52188496
https://blog.cospotato.tech/2017/02/03/阿里云Maven镜像使用的正确姿势/

配置多个仓库

vim /usr/java/apache-maven-3.5.4/conf/settings.xml

增加或修改内容

 <mirrors>
    <mirror>
      <id>ali maven</id>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
    <mirror>    
      <id>ui</id>    
      <mirrorOf>central</mirrorOf>    
      <name>Human Readable Name for this Mirror.</name>    
      <url>http://uk.maven.org/maven2/</url>    
    </mirror>
    <mirror>    
      <id>ibiblio</id>    
      <mirrorOf>central</mirrorOf>    
      <name>Human Readable Name for this Mirror.</name>    
      <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>    
    </mirror>  
 
    <mirror>    
      <id>jboss-public-repository-group</id>    
      <mirrorOf>central</mirrorOf>    
      <name>JBoss Public Repository Group</name>    
      <url>http://repository.jboss.org/nexus/content/groups/public</url>    
    </mirror> 
    <!--访问慢的网址放入到后面-->
     <mirror>    
      <id>CN</id>  
      <name>OSChina Central</name>         
      <url>http://maven.oschina.net/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>    
    </mirror>
    <mirror>    
      <id>net-cn</id>    
      <mirrorOf>central</mirrorOf>    
      <name>Human Readable Name for this Mirror.</name>    
      <url>http://maven.net.cn/content/groups/public/</url>     
    </mirror> 
    <mirror>    
      <id>JBossJBPM</id>  
      <mirrorOf>central</mirrorOf> 
      <name>JBossJBPM Repository</name>   
      <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>  
    </mirror> 
  </mirrors>

来自
https://blog.csdn.net/www1056481167/article/details/60139851?utm_source=blogxgwz0

mirrorOf 说明

1.<mirrorOf>*</mirrorOf>
匹配所有远程仓库。
2.<mirrorOf>external:*</mirrorOf>
匹配所有远程仓库,使用localhost的除外,使用file://协议的除外。也就是说,匹配所有不在本机上的远程仓库。
3.<mirrorOf>repo1,repo2</mirrorOf>
匹配仓库repo1和repo2,使用逗号分隔多个远程仓库。
4.<mirrorOf>*,!repo1</miiroOf>
匹配所有远程仓库,repo1除外,使用感叹号将仓库从匹配中排除。
5.<mirrorOf>central</miiroOf>
值为central, 表示该配置为中央仓库的镜像

https://blog.csdn.net/caomiao2006/article/details/40401517

Maven的settings.xml文件结构之activeProfiles

无论是在pom.xml文件中,还是在settings.xml文件中,都可以配置多个<profile>。但是并非所有的<profile>都会被激活,即该<profile>的配置生效与否,可以通过如下方式进行控制:

  • pom.xml文件中通过<profile><activation>
  • settings.xml文件中通过<profile><activation>
  • settings.xml文件中通过<activeProfiles>
    其中,通过<profile><activation>配置激活对应的<profile>条件,这个在pom.xml文件中和在settings.xml文件中是一致的,详见pom.xml文件的配置。

settings.xml文件中,还可以通过<activeProfiles>直接给出被激活的<profile>(可以有多个),示例如下:

  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>

在上述示例中,默认激活<id>dev</id><profile>。当然,也可以根据需要,默认激活多个<profile>
来自
https://blog.csdn.net/taiyangdao/article/details/52311257

配置pom.xml 的 dev Maven 仓库

<profiles>
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>https://maven.aliyun.com/repository/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <url>https://maven.aliyun.com/repository/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

来自 https://blog.csdn.net/yaoyuncn/article/details/52996240

Maven 自动发布更新本地和远程仓库

编译源码时同时更新本地仓库

mvn  clean package install 
或(跳过测试)
mvn  clean package install -Dmaven.test.skip=true

编译源码时同时更新远程仓库

mvn clean package deploy
或(跳过测试)
mvn  clean package deploy -Dmaven.test.skip=true

Maven 某些错误

[WARNING] The POM for com.alibaba:dubbo:jar:2.8.4 is missing, no dependency information available

[ERROR] Failed to execute goal on project dubbo-monitor: Could not resolve dependencies for project com.handu.open:dubbo-monitor:war:1.0.0: Failure to find com.alibaba:dubbo:jar:2.8.4 in http://maven.aliyun.com/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of alimaven has elapsed or updates are forced -> [Help 1]
以上的错误原因就是本地Maven仓库缺少某些包。
类似以上的错误都可以用这种方法解决
这个是我在本地编译 dubbox-monitor监控端(http://git.oschina.net/handu/dubbo-monitor)所报的错误。
解决方法
1.先把 dubbox(https://github.com/dangdangdotcom/dubbox)下载下来,
解压缩后,进入dubbox目录,
重新用如下命令编译一次

mvn  clean package install -Dmaven.test.skip=true

2.然后进入我要编译的 dubbox-monitor监控端(http://git.oschina.net/handu/dubbo-monitor)目录
执行

mvn  clean package -Dmaven.test.skip=true

这时你就会发现,编译通过了,不用再找烦人的错误了

Maven 代理设置

最简单方法:
直接在后面加上 IP地址和端口

-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=8888

例如要编译 某个东西

mvn clean install -Dmaven.test.skip=true -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=8888

SOCKS5

<proxy>
      <id>my-proxy</id>
      <active>true</active>
      <protocol>socks5</protocol>
      <username></username>
      <password></password>
      <host>127.0.0.1</host>
      <port>8888</port>
      <nonProxyHosts>127.0.0.1</nonProxyHosts>
 </proxy>

http代理

 <proxies>    
   <proxy>    
     <id>my-proxy</id>    
     <active>true</active>    
     <protocol>http</protocol>    
     <host>127.0.0.1</host>    
     <port>8888</port>    
     <username>有就填写没有就删除</username>    
     <password>有就填写没有就删除</password>    
     <nonProxyHosts>127.0.0.1|*.lanmps.com</nonProxyHosts>    
   </proxy>    
 </proxies> 

ANT

yum -y install ant
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风.foxwho

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值