CentOS搭建:Maven
2023/12/31大约 10 分钟
参考:
CentOS搭建:Maven
概要说明
常用命令
环境依赖
软件/系统 | 版本 | 架构 | 包名 | 安装方式 | 备注 |
---|---|---|---|---|---|
Linux | CentOS7.X | x86_64 | |||
Maven | apache-maven-3.9.9-bin | 官网下载 |
CentOS中软件安装的常用方式:
在线源安装(yum)
离线程序安装(rpm)
二进制包安装(无需编译)
源码二进制包安装(无需编译)
源码包编译安装 (要编译)
安装搭建
包下载
下载版本:3.9.9
sudo wget https://archive.apache.org/dist/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
环境检查
mvn -version
创建目录
# 安装目录
sudo mkdir -p /soft/maven
# 仓库目录
sudo mkdir -p /data/maven/repo
解压缩包
sudo tar -zxvf apache-maven-3.9.9-bin.tar.gz -C /soft/maven
修改配置
环境变量
# 查看是否已有配置文件 ll -a /etc/profile.d/ |grep maven # 编辑环境变量文件 sudo vi /etc/profile.d/maven.sh
export MAVEN_HOME=/soft/maven/apache-maven-3.9.9 export PATH=$PATH:$MAVEN_HOME/bin
# 使配置生效 source /etc/profile.d/maven.sh
# 验证是否成功 mvn -version
配置文件(setting.xml)
# 定位到配置目录 cd /soft/maven/apache-maven-3.9.9/conf/ # 备份配置文件 sudo cp settings.xml settings.xml.bak20241115 # 编辑配置文件 sudo vi settings.xml
# 本地仓库路径 <localRepository>/data/maven/repo</localRepository>
# 镜像, <mirror> <id>repo_all_by_repo_aliyun_public</id> <!-- *拦截所有的仓库 --> <mirrorOf>*</mirrorOf> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
完整配置参考
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> <!-- 本地仓库路径 --> <localRepository>/D:/ResLibFiles/Repository/Maven</localRepository> <!-- 连接服务 --> <!-- <servers> <server> <id>maven-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>maven-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> --> <!-- 镜像 --> <mirrors> <mirror> <id>repo_central_by_repo_aliyun_public</id> <!-- 拦截指定id的仓库 --> <mirrorOf>central</mirrorOf> <url>https://maven.aliyun.com/repository/public/</url> </mirror> <mirror> <id>repo_repo1_apache_by_repo_aliyun_public</id> <!-- 拦截指定id的仓库 --> <mirrorOf>repo_repo1_apache</mirrorOf> <url>https://maven.aliyun.com/repository/public/</url> </mirror> <!-- <mirror> <id>repo_central_by_repo_sun_public</id> 拦截指定id的仓库 <mirrorOf>central</mirrorOf> <url>http://maven.cnsuning.com/content/groups/public/</url> </mirror> <mirror> <id>repo_repo1_apache_by_repo_sun_public</id> 拦截指定id的仓库 <mirrorOf>repo_repo1_apache</mirrorOf> <url>http://maven.cnsuning.com/content/groups/public/</url> </mirror> --> <mirror> <id>maven-default-http-blocker</id> <mirrorOf>blocker</mirrorOf> <name>用于突破maven-3.8.1版本以后默认禁用http仓库的限制</name> <url>https://maven.aliyun.com/repository/public/</url> <!--<url>http://maven.cnsuning.com/content/groups/public/</url>--> </mirror> </mirrors> <!-- 配置项 --> <profiles> <!-- 配置1 aliyun仓库============================================================== --> <profile> <!--配置的id --> <id>repo_aliyun</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_aliyun_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://maven.aliyun.com/repository/public/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_aliyun_plugin_public</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://maven.aliyun.com/repository/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置2 sun仓库============================================================== --> <profile> <!--配置的id --> <id>repo_sun</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_sun_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://maven.cnsuning.com/content/groups/public/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_sun_plugin_public</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://maven.cnsuning.com/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置3 repo1仓库============================================================== --> <profile> <!--配置的id --> <id>repo_repo1</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo1</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://repo1.maven.org/maven2/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo1_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://repo1.maven.org/maven2/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置4 repo1-apache仓库============================================================== --> <profile> <!--配置的id --> <id>repo_repo1_apache</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo1_apache</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://repo.maven.apache.org/maven2/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo1_apache_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://repo.maven.apache.org/maven2/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置5 repo2仓库============================================================== --> <profile> <!--配置的id --> <id>repo_repo2</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo2</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://repo2.maven.org/maven2/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_repo2_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://repo2.maven.org/maven2/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置6 spring仓库============================================================== --> <profile> <!--配置的id --> <id>repo_spring</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_spring</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://repo.spring.io/libs-snapshot/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_spring_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://repo.spring.io/libs-snapshot/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置7 uk仓库============================================================== --> <profile> <!--配置的id --> <id>repo_uk</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_uk</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://uk.maven.org/maven2/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_uk_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://uk.maven.org/maven2/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置8 jboss仓库============================================================== --> <profile> <!--配置的id --> <id>repo_jboss</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_jboss_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_jboss_plugin_public</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://repository.jboss.org/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置9 google仓库============================================================== --> <profile> <!--配置的id --> <id>repo_google</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_google</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://maven.google.com/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_google_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://maven.google.com/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置10 china仓库============================================================== --> <profile> <!--配置的id --> <id>repo_china</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_china_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://maven.net.cn/content/groups/public/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_china_plugin_public</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://maven.net.cn/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置11 oschina仓库============================================================== --> <profile> <!--配置的id --> <id>repo_oschina</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_oschina_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://maven.oschina.net/content/groups/public/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_oschina_plugin_public</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://maven.oschina.net/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置12 ibiblio仓库============================================================== --> <profile> <!--配置的id --> <id>repo_ibiblio</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_ibiblio_public</id> <!--仓库地址,即私服仓库组的地址 --> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_ibiblio_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 配置13 cdh仓库============================================================== --> <profile> <!--配置的id --> <id>repo_cdh</id> <!-- 仓库配置项 --> <repositories> <!-- 仓库,项目的运行依赖,需要从私服下载 --> <repository> <!--仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_cdh</id> <!--仓库地址,即私服仓库组的地址 --> <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url> <!--是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <!-- 插件仓库配置项 --> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,需要从私服下载 --> <pluginRepository> <!-- 插件仓库id,不允许重复,如果重复后边配置会覆盖前边 --> <id>repo_cdh_plugin</id> <!-- 插件仓库地址,即私服仓库组的地址 --> <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- 配置项激活 --> <activeProfiles> <activeProfile>repo_aliyun</activeProfile> <!-- <activeProfile>repo_sun</activeProfile> --> <!-- <activeProfile>repo_repo1</activeProfile> --> <!-- <activeProfile>repo_repo1_apache</activeProfile> --> <!-- <activeProfile>repo_repo2</activeProfile> --> <!-- <activeProfile>repo_spring</activeProfile> --> <!-- <activeProfile>repo_uk</activeProfile> --> <!-- <activeProfile>repo_jboss</activeProfile> --> <!-- <activeProfile>repo_google</activeProfile> --> <!-- <activeProfile>repo_china</activeProfile> --> <!-- <activeProfile>repo_oschina</activeProfile> --> <!-- <activeProfile>repo_ibiblio</activeProfile> --> <!-- <activeProfile>repo_cdh</activeProfile> --> </activeProfiles> </settings>