搭建maven私服

news2025/4/24 0:13:27

maven

maven简介

什么是maven?

Maven这个单词来自于意第绪语(犹太语),意为知识的积累

Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。

Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。

maven发展历史

image-20221224185057578

maven的体系结构

image-20221224185416654

maven安装配置

maven下载与配置

下载maven

访问网站 https://maven.apache.org

image-20221225193053478

image-20221225193358873

image-20221225194023576

image-20221225194143162 image-20221225194219474

image-20221225194307487

maven本地配置

打开conf\settings.xml文件

本地仓库位置

配置本地仓库的位置

<localRepository> 本地地址 <localRepository>

image-20221231100718551

<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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  -->
    <localRepository>C:\maven-repository</localRepository>
镜像配置

由于中央仓库在境外,网络访问不稳定,故在开发过程中大多配置中央仓库的镜像仓库。

image-20221231101418977

<mirror>
  <id>aliyunmaven</id>
  <mirrorOf>central</mirrorOf>
  <name>阿里云公共仓库</name>
  <url>https://maven.aliyun.com/repository/public</url>
</mirror>
profile

配置maven默认使用的jdk环境。

image-20221231101536919

<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>

idea环境安装配置maven

在idea中打开File/Settings

image-20221231101822894

image-20221231101900757

配置本地maven
image-20221231102009662 image-20221231102529368

image-20221231102643931

maven核心思想

maven仓库

image-20221224210030934

maven生命周期

image-20221224185546095

maven项目对象模型(pom)

image-20221224185644952

dependency

image-20221224205636197

依赖Scope配置。

序列依赖范围(Scope)对于主代码classpath有效对于测试代码classpath有效被打包,对于运行时classpath有效案例
1compileyesyesyeslog4j
2testyesjunit
3providedyesyesservlet-api
4runtimeyesJDBC Driver Implementtion

maven私服-nexus

下载安装

下载nexus

访问官网: https://help.sonatype.com/repomanager3/product-information/download

image-20221230152153312

由于网络不稳定,下载问题,我选择其它版本nexus-3.40.1-01-unix.tar.gz

image-20221230153020740

上传到linux服务器

image-20221230153444955image-20221230153518060

image-20221230153722055

解压并重名名

解压nexus-3.40.1-01-unix.tar.gz

tar -zxvf nexus-3.40.1-01-unix.tar.gz

image-20221230154026909

image-20221230154059471

nexus配置

进入nexus-3.40.1/bin文件夹

image-20221230154506369

image-20221230154534475
编辑nexus.vmoptions文件

根据自己机器内存大小,适当配置内存。内存太小未来启动nexus会失败。

vim nexus.vmoptions

image-20221230155224205
配置端口

默认端口为8081,如果需要在要在文件中配置端口。(如果不需改端口,此处可以忽略)

  • 进入etc文件夹

    image-20221230155555257
  • 修改nexus-default.properties文件

    image-20221230155709022

    image-20221230155804893

运行nexus

启动nexus

image-20221230155940806

运行命令**./nexus start**

image-20221230160054424
开放linux的8081端口
  • 检查系统开放的端口号

    firewall-cmd --list-ports

    image-20221230160447791
  • 添加8081端口

    firewall-cmd --zone=public --add-port=端口号/tcp --permanent

    image-20221230160812191
  • 重新加载防火墙

    firewall-cmd --reload

    image-20221230160826381
查看nexus的运行状态

在浏览器中输入http://102.168.0.101:8081

image-20221230161445094

image-20221230161508314

修改管理员密码
  • 查看管理员账户密码

    1. 进入sonatype-work\nexus3文件夹

      image-20221230205551738
    2. 查看管理员密码

      image-20221230205629156
  • 修改管理员密码

    1. 浏览器登录nexus

      image-20221230205922783

    2. 修改密码

      image-20221230210005734

      image-20221230210125712

      image-20221230210220617

      image-20221230210254339


配置私有仓库

nexus中默认仓库

maven-releases (Version policy=Release)默认只允许上传不带SNAPSHOT版本尾缀的包,默认部署策略是Disable redeploy 不允许重复上传相同版本号信息的jar,避免包版本更新以后使用方无法获取到最新的包。

maven-snapshots (Version policy=Snapshot)只允许上传带SNAPSHOT版本尾缀的包,默认部署策略是Allow redeploy,允许重复上传相同版本号信息的jar,每次上传的时候会在jar的版本号上面增加时间后缀信息。

maven-central 中央仓库的拷贝,如果环境可以访问中央仓库,则可以获取到相关的包,否则没用

maven-public 仓库组,不是实际个一个仓库地址,只是将现有的组合到一次,可以通过它看到所属组内全部仓库的jar信息

image-20221230210907451

创建自定义仓库

image-20221230211115408

image-20221230211211724

选择maven2(hosted)

image-20221230211532124

image-20221230211800395

添加新建仓库到maven-public群组中
  • 选中maven-public群组,之后访问maven-public就可以访问自己的私有仓库了。

    image-20221230212044626

  • 创建三个仓库,wnhz-repository(混合拍照&发布), wnhz-releases(发布版), wnhz-snapshots(拍照班)

    image-20231022164215854

    照片版(测试版/开发版)

    image-20231022164542564

    发布版
    在这里插入图片描述

    混合版

在这里插入图片描述

  • 添加仓库到群组maven-public群组中

    image-20231022165333619

在这里插入图片描述

批量上传本地文件到自定义仓库中

上传本地仓库内容到linux服务器
image-20221230213556643

image-20221230213627584

编辑批量上传脚本

在本地仓库上传的文件夹(maven-repository)下创建一个shell脚本,命名 localrepository.sh

  • 创建脚本

    touch localrepository.sh

    image-20221230215900056
  • 编辑脚本

    vim localrepository.sh

    #!/bin/bash
    while getopts ":r:u:p:" opt; do
        case $opt in
            r) REPO_URL="$OPTARG"
            ;;
            u) USERNAME="$OPTARG"
            ;;
            p) PASSWORD="$OPTARG"
            ;;
        esac
    done
      
    find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
    

    image-20221230220027490

添加权限

给脚本localrepository.sh添加执行权限

chmod +x localrepository.sh

image-20221230220208762
导入本地仓库到nexus私有仓库

执行以下命令

./localrepository.sh -u nexus用户名 -p nexus密码 -r 仓库地址(自定义存储混合依赖的)

 ./localrepository.sh -u admin -p 123 -r http://192.168.198.128:8081/repository/wnhz-repository/

在这里插入图片描述

在这里插入图片描述

image-20221230220912896

image-20231022165629991

项目中引用nexus库

在maven的conf/settings.xml中配置server

在settings中配置snapshots,releases和wnhz-repository服务用户名密码

注意:id必须唯一,项目pom中引用的是这个指定id。

 <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  	<server>
  		<id>wnhz</id>
  		<username>admin</username>
  		<password>123</password>
  	</server>
    <server>
      <id>wnhz-release</id>
      <username>admin</username>
      <password>123</password>
    </server>
    <server>
      <id>wnhz-snapshots</id>
      <username>admin</username>
      <password>123</password>
    </server>
  </servers>

在这里插入图片描述

在maven中配置镜像

中央仓库的资源从阿里云访问,其它资源来自nexus私服。

image-20221231104454031

  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.   
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
   
     -->
   <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>central</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
    <mirror>
      <id>wnhzmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>蜗牛杭州的maven私服仓库</name>
      <url>http://192.168.198.128:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>

私服访问地址从下图获取:http://192.168.198.128:8081/#browse/browse:maven-public

image-20231022170313546

项目中配置发布管理

在项目的pom.xml文件中添加<distributionManagement>

   <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>${project.druid.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <distributionManagement>
        <snapshotRepository>
            <id>wnhz-snapshots</id>
            <url>http://192.168.198.128:8081/repository/wnhz-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>wnhz-releases</id>
            <url>http://192.168.198.128:8081/repository/wnhz-releases/</url>
        </repository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>nexus</id>
            <url>http://192.168.198.128/repository/wnhz-repository/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

部署项目

在maven中运行部署,部署(deploy)项目到私服。

在这里插入图片描述

在这里插入图片描述

项目中maven配置

<parenta>

继承父项目模块

<parent>
    <artifactId>wnhz-bm</artifactId>
    <groupId>com.wnhz.bm</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

当前模块坐标

<modelVersion>4.0.0</modelVersion>
<groupId>com.wnhz.bm.common</groupId>
<artifactId>bm-common</artifactId>
<packaging>pom</packaging>

packaging配置

序列参数解释
1pom表示父类型
2jar打包为jar包
3war打包为war包

module

配置项目的子模块名称

<modules>
    <module>bm-common</module>
    <module>bm-domain</module>
    <module>bm-book</module>
</modules>

properties

定义依赖的版本号

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <druid.version>1.2.18</druid.version>
</properties>

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>${druid.version}</version>
</dependency>

dependencies

引入依赖

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>${druid.version}</version>
    </dependency>
</dependencies>

build

构建项目模块

插件
编译插件
 <!-- 编译源代码插件 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
打包源码插件
   <build>
        <plugins>
            <!-- 编译源代码插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <!-- 打包源代码插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
springboot打包插件

打包将jar包放到项目的更目录out下。

image-20231225190022695

   <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <outputDirectory>../../out</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

私服配置

distributionManagement

部署管理,适用于依赖上传

   <snapshotRepository>
            <id>wnhz-snapshots</id>
            <url>http://192.168.201.81:8081/repository/wnhz-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>wnhz-releases</id>
            <url>http://192.168.201.81:8081/repository/wnhz-releases/</url>
        </repository>
repositories

部署依赖下载

  <repositories>
        <repository>
            <id>nexus</id>
            <url>http://192.168.201.81:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

ory/wnhz-snapshots/


wnhz-releases
http://192.168.201.81:8081/repository/wnhz-releases/


#### repositories

> 部署依赖下载

```xml
  <repositories>
        <repository>
            <id>nexus</id>
            <url>http://192.168.201.81:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1345735.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

算法训练day53|动态规划part14

参考&#xff1a;代码随想录 1143.最长公共子序列 重点&#xff1a;状态的转移与递推公式的确定 本题和动态规划&#xff1a;718. 最长重复子数组 (opens new window)区别在于这里不要求是连续的了&#xff0c;但要有相对顺序&#xff0c;即&#xff1a;"ace" 是 …

Spark任务调度与数据本地性

Apache Spark是一个分布式计算框架&#xff0c;用于处理大规模数据。了解Spark任务调度与数据本地性是构建高效分布式应用程序的关键。本文将深入探讨Spark任务调度的流程、数据本地性的重要性&#xff0c;并提供丰富的示例代码来帮助大家更好地理解这些概念。 Spark任务调度的…

小程序面试题 | 17.精选小程序面试题

&#x1f90d; 前端开发工程师&#xff08;主业&#xff09;、技术博主&#xff08;副业&#xff09;、已过CET6 &#x1f368; 阿珊和她的猫_CSDN个人主页 &#x1f560; 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 &#x1f35a; 蓝桥云课签约作者、已在蓝桥云…

自然语言处理2——轻松入门情感分析 - Python实战指南

目录 写在开头1.了解情感分析的概念及其在实际应用中的重要性1.1 情感分析的核心概念1.1.1 情感极性1.1.2 词汇和上下文1.1.3 情感强度1.2 实际应用中的重要性 2. 使用情感分析库进行简单的情感分析2.1 TextBlob库的基本使用和优势2.1.1 安装TextBlob库2.1.2 文本情感分析示例2…

【Electron】webview 实现网页内嵌

实现效果&#xff1a; 当在输入框内输入某个网址后并点击button按钮 , 该网址内容就展示到下面 踩到的坑&#xff1a;之前通过web技术实现 iframe 标签内嵌会出现 同源策略&#xff0c;同时尝试过 vue.config.ts 内配置跨域项 那样确实 是实现啦 但不知道如何动态切换 tagert …

全球日光地图分布地图数据

日光地图分布地图数据 Daylight 是全球开放地图数据的完整分发版&#xff0c;可在社区和专业地图制作者的支持下免费获取。我们将 OpenStreetMap 等项目的全球贡献者的工作与日光制图合作伙伴的质量和一致性检查结合起来&#xff0c;创建免费、稳定且易于使用的街道比例全球地…

Java EE 网络原理之HTTPS

文章目录 1. HTTPS 是什么&#xff1f;2. "加密" 是什么&#xff1f;3. HTTPS 的工作过程3.1 引入对称加密3.2 引入非对称加密3.3 中间人攻击3.4 引入证书 4. Tomecat4.1 tomcat 的作用 1. HTTPS 是什么&#xff1f; HTTPS也是⼀个应用层协议&#xff0c;是在 HTTP …

C#使用switch语句更改窗体颜色

目录 一、示例 二、生成 用switch多路选择语句及窗体的BackColor属性更改窗体的BackColor属性。该属性用于获取或设置控件的背景颜色。 可以使用Color结构的静态属性获取Color对象&#xff0c;如Color.Red&#xff1b;也可以使用Color结构的静态方法Color.FromArgb()&#xf…

探索人工智能OCR:解放你的文字世界

嘿&#xff01;你听说过人工智能OCR吗&#xff1f;它是一项超酷的技术&#xff0c;让我们来看看它带来的种种好处&#xff1a; 自动化处理&#xff1a;再也不用费力去手动输入和处理大量的纸质文件啦&#xff01;有了人工智能OCR&#xff0c;它能够自动将印刷或手写的文本转换…

C++day4作业

定义一个Person类&#xff0c;私有成员int age&#xff0c;string &name&#xff0c;定义一个Stu类&#xff0c;包含私有成员double *score&#xff0c;写出两个类的构造函数、析构函数、拷贝构造和拷贝赋值函数&#xff0c;完成对Person的运算符重载(算术运算符、条件运算…

Matlab:K-means算法

K-means算法是一种常见的聚类算法&#xff0c;它将一组数据划分为K个不同的簇&#xff0c;以最小化每个簇内部数据点与簇中心之间的平方距离的总和为目标实现聚类。 1、基本步骤&#xff1a; 1.选择要划分的簇数K&#xff1b; 2.选择K个数据点作为初始的聚类中心&#xff1b…

探索 3D 图形处理的奥秘

最近一年多来&#xff0c;在 3Dfx、Intel 们的狂轰滥炸中&#xff0c;在 Quake、古墓丽影们的推波助澜下&#xff0c;三维图形已经成为计算机迷眼中的又一个热点。3D 世界到底是怎样的神奇&#xff0c;我们又是怎样享受它的乐趣呢&#xff1f;就让我们来一探究竟吧。 图形基础…

51单片机的中断相关知识

51单片机的中断相关知识点 一、中断概念和功能 概念 程序执行过程中CPU会遇到一些特殊情况&#xff0c;是正在执行的程序被“中断”&#xff0c;cpu中止原来正在执行的程序&#xff0c;转到处理异常情况或特殊事件的程序去执行&#xff0c;结束后再返回到原被中止的程序处(断…

使用SecoClient软件连接L2TP

secoclient软件是华为防火墙与友商设备进行微屁恩对接的一款软件,运行在windows下可以替代掉win系统自带的连接功能,因为win系统自带的连接功能总是不可用而且我照着网上查到的各种方法调试了很久都调不好,导致我一度怀疑是我的服务没搭建好,浪费了大把时间去研究其他搭建方案 …

Spring Boot快速搭建一个简易商城项目【完成登录功能且优化】

完成登录且优化&#xff1a; 未优化做简单的判断&#xff1a; 全部异常抓捕 优化&#xff1a;返回的是json的格式 BusinessException&#xff1a;所有的错误放到这个容器中&#xff0c;全局异常从这个类中调用 BusinessException&#xff1a; package com.lya.lyaspshop.exce…

dev express 15.2图表绘制性能问题(dotnet绘图表)

dev express 15.2 绘制曲线 前端代码 <dxc:ChartControl Grid.Row"1"><dxc:XYDiagram2D EnableAxisXNavigation"True"><dxc:LineSeries2D x:Name"series" CrosshairLabelPattern"{}{A} : {V:F2}"/></dxc:XYDi…

TOGAF架构开发方法

TOGAF针对架构开发方法定义了一系列阶段和步骤&#xff0c;这些阶段和步骤对架构的迭代过程进行了详细、标准的描述。 企业架构的项目过程 一、预备阶段&#xff08;Preliminary&#xff09; 1、目标 预备阶段的目标是&#xff1a; 对组织的背景和环境进行审查&#xff08;调…

C# 使用ZXing.Net生成带Logo的二维码

写在前面 这是ZXing.Net类库的系列文章&#xff0c;实现在二维码中间插入一个logo图标 C# 使用ZXing.Net生成二维码和条码-CSDN博客 C# 使用ZXing.Net识别二维码和条码-CSDN博客 代码实现 该段代码主体来自其他文章&#xff0c;贴在这做个记录 /// <summary> /// 生成…

基于Python的B站排行榜大数据分析与可视化系统

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长 QQ 名片 :) 1. 项目简介 本文介绍了一项基于Python的B站排行榜大数据分析与可视化系统的研究。通过网络爬虫技术&#xff0c;系统能够自动分析B站网址&#xff0c;提取大量相关文本信息并存储在系统中。通过对这些信息进行…

【Kubernetes】kubectl 常用命令

kubectl 常用命令 1.基础命令2.部署命令3.集群管理命令4.故障诊断与调试命令5.高级命令6.设置命令7.其他命令 kubectl 是 Kubernetes 提供的命令行管理工具。通过使用 kubectl&#xff0c;可以管理和操作 Kubernetes。 1.基础命令 命令 说明 create通过文件名或标准输入创建 …