阿里云基础开发环境搭建与维护系列之二 : Maven安装与配置

我们经常需要搭建开发环境,或将客户的服务部署到服务器上,以正式发布程序,这都需要采购服务器,然后搭建开发环境,并做日常维护。本文以阿里云服务器为例,记录java开发/部署环境的的搭建与维护。
操作系统:CentOS 8.2

购买好阿里云服务器后,通过ssh登录服务器,创建软件包存放文件夹,用于存放后续待使用的文件包:

sudo mkdir /root/software_packages

然后通过wget命令在服务器上直接下载下文所需软件包,或者在本地windows客户端下载好软件包后,通过winscp上传至服务器。

二、Maven安装与配置

同样,maven安装以手动下载安装为例:

  1. 在Apache官网下载所需版本maven文件(以apache-maven-3.6.3-bin.tar.gz为例),上传至阿里云服务器;
  2. 服务器创建maven安装路径
# 创建maven安装目录
sudo mkdir /usr/lib/maven
  1. 将maven文件解压到安装路径
# 解压缩到安装目录
sudo tar -zxvf /root/software_packages/apache-maven-3.6.3-bin.tar.gz -C /usr/lib/maven/

这样maven就安装好了,接下来需要配置环境变量

  1. 配置maven环境变量,将maven环境变量信息写入/etc/profile文件中
# 使用vim打开/etc/profile文件
vim /etc/profile

在文件末尾写入以下内容:

# maven
export MAVEN_HOME=/usr/lib/maven/apache-maven-3.6.3
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin

保存退出后,务必要执行更新命令

# 更新profile文件使之立即生效
source /etc/profile

验证是否安装成功

# 验证安装
mvn -version
  1. 这样,maven就安装完成。接下来修改配置文件,使用国内镜像
# 进入maven配置文件夹
cd /usr/local/maven/apache-maven-3.6.3/conf
# 将settings.xml文件夹重命名(或者删除)
mv settings.xml settings.xml.bak

然后将下面的settings.xml文件通过scp命令或winscp工具传入到/usr/local/maven/apache-maven-3.6.3/conf/文件夹中即可

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>mirror</id>
            <mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf>
            <name>mirror</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>

    </mirrors>
    <servers>
        <server>
            <id>rdc-releases</id>
            <username>cApIx6</username>
            <password>DcKvDiFJ85</password>
        </server>
        <server>
            <id>rdc-snapshots</id>
            <username>cApIx6</username>
            <password>DcKvDiFJ85</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>rdc</id>
            <properties>
                <altReleaseDeploymentRepository>
                    rdc-releases::default::https://repo.rdc.aliyun.com/repository/76226-release-psMKXc/
                </altReleaseDeploymentRepository>
                <altSnapshotDeploymentRepository>
                    rdc-snapshots::default::https://repo.rdc.aliyun.com/repository/76226-snapshot-0PejqM/
                </altSnapshotDeploymentRepository>
            </properties>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-releases</id>
                    <url>https://repo.rdc.aliyun.com/repository/76226-release-psMKXc/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-snapshots</id>
                    <url>https://repo.rdc.aliyun.com/repository/76226-snapshot-0PejqM/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-releases</id>
                    <url>https://repo.rdc.aliyun.com/repository/76226-release-psMKXc/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-snapshots</id>
                    <url>https://repo.rdc.aliyun.com/repository/76226-snapshot-0PejqM/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>rdc</activeProfile>
    </activeProfiles>
</settings>

这样maven的安装配置就完成了。

系列文章

  1. 阿里云基础开发环境搭建与维护系列之一 : JAVA安装与配置
  2. 阿里云基础开发环境搭建与维护系列之二 : Maven安装与配置
  3. 阿里云基础开发环境搭建与维护系列之三 : Git安装与配置
  4. 阿里云基础开发环境搭建与维护系列之四 : MySQL安装与配置
  5. 阿里云基础开发环境搭建与维护系列之五 : Redis安装与配置
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容