centos7 nexus3版maven私服配置

一、安装nexus3

https://blog.csdn.net/u010375456/article/details/95041237

二、maven仓库介绍

A、maven-central:这是maven的中心仓库,nexus这里只是做一个代理,最后会转发到maven的central库

B、maven-public:这是一个仓库组,访问这个仓库组的地址其实会访问组内所有仓库 

C、maven-releases:这是nexus提供的一个默认的存放release版本jar包的仓库

D、maven-snapshots:这是nexus提供的一个默认的存放snapshot版本jar包的仓库

三、上传jar包

1、上传jar需要认证,在maven的settings.xml文件中配置。

这里配置两个用户,一个部署release类型jar包的,一个是部署snapshot类型jar包的,密码根据自己实际情况配置。

id用于唯一指定一条认证配信息,之后会在pom中使用。

 2、接着新建一个quick-start的maven项目,在pom中配置distributionManagement标签,该标签负责描述maven deploy上传远程仓库

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.jhtech</groupId>
  <artifactId>mavenTest</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>mavenTest</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <distributionManagement>
    <repository>
      <id>release_user</id>
      <name>Release Deploy</name>
      <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
      <id>snapshot_user</id>
      <name>Snapshot Deploy</name>
      <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

</project>

这里配置了上传的url,具体的url可以在nexus的仓库浏览界面下点击仓库的url copy获得。使用刚才的两个认证信息,把jar包存在nexus提供的默认仓库下。id对应了setting.xml里配置的信息,name随意。

3、项目中执行,部署jar到nexus上

mvn clean deploy

4、nexus服务器显示对应的jar 

四、拉取jar包

1、新建一个maven的quick-start项目,然后需要在pom中加入依赖,并且配置我们的nexus仓库

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.jhtech</groupId>
  <artifactId>mavenTest2</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>mavenTest2</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.jhtech</groupId>
      <artifactId>mavenTest</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>nexus-public</id>
      <name>Nexus Public</name>
      <url>http://localhost:8081/repository/maven-public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
</project>

2、执行命令

mvn clean package

3、本地项目已经有对应jar包

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章