君玉自牧 君玉自牧
首页
  • Linux
  • Nginx
  • MySQL
  • Redis
  • Kafka
  • Docker
  • Jenkins
  • Oneindex
  • Bitwarden
  • Confluence
  • Photogallery
  • 智能手机
  • 上古卷轴
  • 健身记录
  • 站点相关
  • 未完待续
GitHub (opens new window)
首页
  • Linux
  • Nginx
  • MySQL
  • Redis
  • Kafka
  • Docker
  • Jenkins
  • Oneindex
  • Bitwarden
  • Confluence
  • Photogallery
  • 智能手机
  • 上古卷轴
  • 健身记录
  • 站点相关
  • 未完待续
GitHub (opens new window)
  • 技术架构

  • 桌面维护

  • 网络工程

  • 系统运维

  • 环境搭建

    • 适用于 Linux 的 Windows 子系统(WSL)- CentOS
    • Windows 开启 WSL 搭建 Docker & K8s 环境
    • Rancher Desktop 搭建 K3s 单机环境
    • Multipass 虚拟机体验 Ubuntu
    • Windows 11 搭建 WSA 环境运行 Android 应用
    • 虚拟电脑:VirtualBox 虚拟机
    • Linux 系统搭建 Java 环境
    • Linux 系统搭建 PHP 环境
    • Linux 系统搭建 Node.js 环境
    • Linux 系统搭建 .NET 环境
    • Linux 系统搭建 Maven 环境
      • 解压安装
      • 环境变量
      • 环境验证
      • 修改设置
  • 容器编排

  • 持续集成

  • 监控告警

  • 项目实践

  • 脚本开发

  • 前端开发

  • 后端开发

  • 效率工具

目录

Linux 系统搭建 Maven 环境

直接官网下载 Maven (opens new window) 然后解压安装,离线安装的话请先下载好上传到服务器

wget https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz
1

# 解压安装

tar -zxvf apache-maven-3.8.7-bin.tar.gz -C /app/service
mv /app/service/apache-maven-3.8.7 /app/service/maven
1
2

顺便创建本地仓库文件夹

mkdir -pv /app/data/maven/repo
1

# 环境变量

设置当前用户环境变量:~/.bashrc,继承 /etc/profile 中的变量

echo "export MAVEN_HOME=/app/service/maven" >> ~/.bashrc
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" >> ~/.bashrc
1
2

# 环境验证

source ~/.bashrc
mvn -version
1
2

# 修改设置

修改 maven 目录下的settings.xml文件

mv /app/service/maven/conf/settings.xml /app/service/maven/conf/settings.xml.bak
vi /app/service/maven/conf/settings.xml
1
2
<settings>
  <!--设置本地仓库位置-->
  <localRepository>/app/data/maven/repo</localRepository>

  <servers>
    <!--设置私库认证信息(访问)-->
    <server>
      <id>nexus</id>
      <username></username>
      <password></password>
    </server>

    <!--设置私库认证信息(发布)-->
    <server>
      <id>nexus-releases</id>
      <username></username>
      <password></password>
    </server>

    <server>
      <id>nexus-snapshots</id>
      <username></username>
      <password></password>
    </server>
  </servers>

  <mirrors>
    <!--设置私有仓库,Maven 所有的请求都由私库处理-->
    <mirror>
      <id>nexus</id>
      <name>Nexus Releases Repository</name>
      <mirrorOf>*</mirrorOf>
      <url>http://192.168.254.100:8081/repository/public/</url>
    </mirror>

    <!--设置阿里云公共仓库-->
    <mirror>
      <id>aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public/</url>
    </mirror>
  </mirrors>

  <profiles>
    <!--设置 JDK 版本-->
    <profile>
      <id>jdk-1.8</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>

    <!--设置私库信息-->
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus Releases Repository</name>
          <url>http://192.168.254.100:8081/repository/public/</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>nexus</id>
          <name>Nexus Releases Repository</name>
          <url>http://192.168.254.100:8081/repository/public/</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>

    <!--覆盖中央仓库设置,开启 releases 和 snapshots 版本的下载-->
    <profile>
      <id>central</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <!--激活私库信息-->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>central</activeProfile>
  </activeProfiles>
</settings>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
网页编辑 (opens new window)
最近提交: 2023/03/22, 11:52:35
Linux 系统搭建 .NET 环境
Docker 安装部署 & 常规配置

← Linux 系统搭建 .NET 环境 Docker 安装部署 & 常规配置→

Theme by Vdoing | Copyright © 2011-2023 | 君玉自牧
粤ICP备15057965号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式