YAZONG 我的开源

maven搭建nexus私服并在IDE中配置pom.xml

  ,
0 评论0 浏览

首先注明一下:下方的内容中个别图片是从几个网站中黏贴进来的,时间太长忘记注明来源了,原作者看见能提醒我下,我注明,抱歉!下方大多数是自己总结的,有些描述的比较细,只是论述了个人能理解的部分。如果不知道 maven 如果在 myeclipse 中配置,那么请看我上篇博文:"maven 在 myeclipse8.6 中的配置 http://ylcodes01.blog.51cto.com/5607366/1771647"。

1、简介

这里主要是对 maven 和 nexus 私服的使用。nexus 私服,可以理解为在本地局域网建立了一个类似中央仓库的处理器,我们开始将资料下载到中央服务器中,然后在本地 maven 项目中直接访问中央服务器即可,这样既

节省了网络宽带也会加速项目的开发进度,图如下展示:

Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客.png

2、下载私服到本地并安装

http://www.sonatype.org/nexus/go/

点击 NUEXS OSS(ZIP),会让输入邮箱,无视即可,如果不自动下载,那么复制 URL 链接到迅雷即可下载。

比如:https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-latest-bundle.zip

解压 nexus-latest-bundle.zip,进入 E:\nexus\nexus-latest-bundle-zip\nexus-2.11.4-01\bin\jsw\windows-x86-64

双击 console-nexus.bat 安装,会弹出 DOS 框,等着安装完,中间别关掉 DOS 框。

Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客1.png

3、操作 NEXUS

游览器中输入 http://127.0.0.1:8081/nexus/,出现如下图所示就代表 nexus 已经启动成功。

8081 为默认的端口号,要修改端口号可进入 nexus-2.1.2-bundle\nexus-2.1.2\conf\打开 nexus.properties 文件,修改 application-port 属性值就可以了。

默认的用户名和密码:admin/admin123,登录后看到如下图所示:

Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客2.png

下面关于上述图中某几列的解释:


TYPE:

hosted 类型的仓库,内部项目的发布仓库

releases 内部的模块中 release 模块的发布仓库

snapshots 发布内部的 SNAPSHOT 模块的仓库

proxy 类型的仓库,从远程中央仓库中寻找数据的仓库

group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库


REPOSITORY:

PublicRepositories: 仓库组

3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库(个人理解操作:maven 仓库中没有的,需要手工传到仓库中的 jar 包)

Apache Snapshots: 用了代理 ApacheMaven 仓库快照版本的构件仓库

Central: 用来代理 maven 中央仓库中发布版本构件的仓库(个人理解操作:maven 仓库)

Central M1 shadow: 用于提供中央仓库中 M1 格式的发布版本的构件镜像仓库

Codehaus Snapshots: 用来代理 CodehausMaven 仓库的快照版本构件的仓库

Releases: 用来部署管理内部的发布版本构件的宿主类型仓库

Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库


理解:

一般用到的仓库种类是 hosted、proxy。Hosted 代表宿主仓库,用来发布一些第三方不允许的组件,比如 oracle 驱动、比如商业软件 jar 包。Proxy 代表代理远程的仓库,最典型的就是 Maven 官方中央仓库、JBoss 仓库等等。如果构建的 Maven 项目本地仓库没有依赖包,那么就会去这个代理站点去下载,那么如果代理站点也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是 proxy。代理站点下载成功后再下载至本机。笔者认为,其实 Maven 这个自带的默认仓库一般情况下已经够大多数项目使用了。特殊情况时在配置新的仓库,指定 url 即可,一般熟悉 ExtJS 的人操作这个 Nexus 都没什么问题,单词不是很难,不明白的查查单词基本差不多。就是如果 Sonatype 公司对其做了国际化的处理就更好了。

Nexus 中仓库组的概念是 Maven 没有的,在 Maven 看来,不管你是 hosted 也好,proxy 也好,或者 group 也好,对我都是一样的,我只管根据 groupId,artifactId,version 等信息向你要构件。为了方便 Maven 的配置,Nexus 能够将多个仓库,hosted 或者 proxy 合并成一个 group,这样,Maven 只需要依赖于一个 group,便能使用所有该 group 包含的仓库的内容。


4、nexus 配置(maven 的配置参考 maven-使用部分。)

4、1 利用现有 nexus 索引配置

需要的索引有 Public Repositories,3rd party 和 Central。如果新建的 nexus 跟下述图中的属性不一致,需要调整。


Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客3.png

在 myeclipse 中的 maven 工程配置 pom.xml,大致内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>MavenTest01</groupId>
  <artifactId>MavenTest01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <!-- 版本属性 -->
<properties>
<!-- lib version setting -->
<spring.version>4.1.6.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis-spring.version>1.2.2</mybatis-spring.version>
<mysql.driver.version>5.1.35</mysql.driver.version>
<druid.version>1.0.13</druid.version>
<!-- project util lib version setting -->
<util.version>0.2.2-SNAPSHOT</util.version>
<!-- util lib version setting -->
<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.7</slf4j.version>
<jackson.version>2.5.1</jackson.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-beanutils.version>1.9.2</commons-beanutils.version>
<httpClient.version>4.5</httpClient.version>
<gson.version>2.2.4</gson.version>
<junit.version>4.11</junit.version>
<!-- 编译jdk版本 -->
<jdk.version>1.7</jdk.version>
</properties>
<!-- 设定主仓库 -->
<repositories>
<!-- nexus私服 -->
<repository>
<id>nexus-repos</id>
<name>Team Nexus Repository</name>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 设定插件仓库 -->
<pluginRepositories>
<pluginRepository>
<id>nexus-repos</id>
<name>Team Nexus Repository</name>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>odbc</artifactId>
  <version>10.1.0.2.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
<finalName>MavenTest01</finalName>
</build>
</project>

Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客4.png


4、2 如果不使用 nexus 已存在的索引,需要新建本地 nexus 索引的话,那么大致内容同上述 nexus 已配置好的索引内容。


注意,下述自己新建的部分弄完之后别忘记保存和 repair index 操作。

在 maven 项目中的 pom.xml 需修改 URL 为: http://127.0.0.1:8081/nexus/content/groups/public-snapshots/ ,其他内容同上述 pom.xml。

当 pom.xml 改造完成之后,注意:maven 项目会先从本地 nexus 仓库中取对应的 jar 包,如果本地仓库没有,那么就会去外网 maven 仓库中去取 jar 包。


Screenshot20200105maven搭建nexus私服在myeclipse中的使用你可以选择不平凡51CTO博客5.png


标题:maven搭建nexus私服并在IDE中配置pom.xml
作者:yazong
地址:https://blog.llyweb.com/articles/2016/05/10/578161732665.html