Table of Contents
Using nexus to build a LAN private server
1. Understanding the maven warehouse
1.1 The role of the maven warehouse
1.2 Maven warehouse classification
四. 局域网使用maven私服
4.1 单个项目使用maven私服
4.2 全局指定私服
Home Java javaTutorial Use nexus to build a LAN private server

Use nexus to build a LAN private server

Jul 23, 2017 pm 03:00 PM
maven local area network private server

Using nexus to build a LAN private server

1. Understanding the maven warehouse

1.1 The role of the maven warehouse

I think back to the time when maven was not used before, we used the original project skeleton of eclipse When building a project, there is often a lib folder in the project directory to store the jar files required for the project. Every time a new project is built, there will be such a lib folder. Then copy the jar into the lib folder configuration path. Obviously there is a lot of repeated work, and the jar packages used in different projects are different, so we need to slowly distinguish them. Then we used project management tools such as svn or git, and we needed to introduce a large number of jar files into the code base, which was not very appropriate.
 Maven can help us solve these problems. The maven warehouse is a location specifically used to store jar files (it can also be used to store project war, zip, pom and other files). Each jar file is assigned a coordinate in the maven warehouse, such as the jstl jar package:

<groupid>javax.servlet</groupid>        组ID
<artifactid>jstl</artifactid>           构建ID
...  其余属性后续介绍
Copy after login

In this way, maven can easily control the project dependency version. Simply put, the maven warehouse helps us manage project components in a unified manner.

1.2 Maven warehouse classification

Use nexus to build a LAN private server##  The query path of project construction: first query the local warehouse, if not found, the central warehouse will be queried, if not found, an error will be reported. The central warehouse address is:

  1. Private server nexus uses

  2. . It is recommended to use the

  3. above. Three are more common and are used more often in projects. However, due to the slow download speed and incomplete jar files in the warehouse, actual enterprise development requires us to build a private server warehouse.

    2. Install and use nexus

     Note here that building a maven private server is not just a tool. The version used by the blogger is nexus-2.12.0.


  4. Click to download, password: 1ar1

  5. Unzip after downloading is complete Yes, after decompression is completed, you can see it in the directory nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin\jsw:

    Use nexus to build a LAN private server

  6. ## The blogger's computer is 64-bit, so open the last folder:

  7. Use nexus to build a LAN private server

  8. Click on the second bat file to set it as a windows service, open nexus and visit the URL: http: //localhost:8081/nexus/ opens the following page after startup, which means nexus is installed and started successfully.
  9. Use nexus to build a LAN private server3. Configure maven private server

  10. #Click Login in the upper right corner to log in

    . The initial account is admin and the password is admin123. It can be modified after successful login. You can find your account password yourself.

  11. Click on the navigation Respositories

    on the left.
    Use nexus to build a LAN private server

  12. You can see that there are some warehouses by default. The meaning of warehouse type Type:

    hosted host warehouse, used Publish some components that are not allowed by third parties, such as jar packages of commercial software such as Oracle drivers
  • proxy proxy remote warehouses, such as the three maven remote warehouses written above. If certain jar files do not exist locally, they will be downloaded from these proxy sites.
  • releases The release warehouse of the release module in the internal module
  • snapshots The warehouse where the internal snapshot module is released
  • 3rd party is a third-party dependent warehouse. After uploading the jar package locally, use the
  • group warehouse to add other warehouses to facilitate developers to set up
  • Start building the private server warehouse. It is worth noting: maven project index: the maven project index is used to facilitate the search for related dependency builds on the private server site. Therefore, before building a private server, you should download the maven index, which is about tens of MB:


Use nexus to build a LAN private serverChange the Download Remote Indexes property to True, and then click save. You can view it in the menu bar Scheduled Tasks The progress of downloading the index.

3.

Add your own proxy remote library
, sometimes our project needs to introduce some special jar files, such as some jar packages of Jboss. At this time, we can also proxy the remote warehouse in the private server. :
Use nexus to build a LAN private serverClick add to add the proxy type, fill in the id, name and url in order. In this case,

no longer needs to be configured in the project

Remote warehouse:

<repository>
    <id>jboss</id>
    <name>JBoss Repository</name>
    <url>;/url>
    <releases>
        <updatepolicy>daily</updatepolicy><!-- never,always,interval n -->
        <enabled>true</enabled>
        <checksumpolicy>warn</checksumpolicy><!-- fail,ignore -->
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <layout>default</layout>
</url></repository>
Copy after login

4.Use nexus to build a LAN private server的使用,上面提到的一些特殊的商业性质相关的jar文件,比如oracle的驱动包,ojdbc.jar并不支持远程下载,这时候可以将我们本地下载好的jar包上传到私服。
Use nexus to build a LAN private server

注意GAV设置要与你pom.xml中一致,上传后添加到Artifacts点击上传即可:
Use nexus to build a LAN private server2
5.由于私服仓库数量过多,导致配置复杂度提高,所以需要用到上述的group类型仓库:
Use nexus to build a LAN private server

切记点击刷新,刷新后点击唯一的一个group仓库,点击配置Configuration就可以看到刚才我们手动添加的代理仓库,然后将代理仓库添加到组仓库,这样依赖,项目中之需要配置组仓库的url就可以访问多个私服仓库。

四. 局域网使用maven私服

4.1 单个项目使用maven私服

在上述步骤完成后,即可在项目中引用私服,pom.xml中改变默认下载仓库url:
指定私服仓库,我的ip是170,不要全盘复制

<repositories>  
    <repository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </repository>  
</repositories>
Copy after login

指定插件仓库

<pluginrepositories>  
    <pluginrepository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </pluginrepository>  
</pluginrepositories>
Copy after login

配置好之后就可以从私服下载依赖包了。但是这种方式只能在改项目中起作用,每次配置项目都需要写两遍,为了将懒人模式进行到底,我们还可以指定全局的私有仓库。

4.2 全局指定私服

找到maven文件的中的Use nexus to build a LAN private server文件
Use nexus to build a LAN private server

在Use nexus to build a LAN private server中添加配置:
在profiles

>标签下添加

<profile>
    <repositories>
        <id>central</id>
        <name>central</name>
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>
        <layout>default</layout>
        <releases>
            <enabled>true<enabled>
        </enabled></enabled></releases>
        <snapshots>
            <enabled>true<enabled>
        </enabled></enabled></snapshots>
    </repositories>
</profile>
Copy after login

配置好之后激活profile

<activeprofiles>  
    <activeprofile>central</activeprofile>  
</activeprofiles>
Copy after login

这样一来,这台电脑上所有maven项目下载jar文件时都会先访问局域网170的电脑。

-----------------------------------windows配置私服完毕-----------------------------------

扩展:setting,xml中各标签的意义

  1. servers(服务器)

<servers>
    <server>
        <id>server001</id>
        <username>my_login</username>
        <password>my_password</password>
        <privatekey>${usr.home}/.ssh/id_dsa</privatekey>
        <passphrase>some_passphrase</passphrase>
        <filepermissions>664</filepermissions>
        <directorypermissions>775</directorypermissions>
        <configuration></configuration>
    </server>
</servers>
Copy after login

id与pom.xml中distributionManagement的id保持一致,服务器标识
username和password表示服务器认证需要的用户民和密码
privateKey, passphrase一组密钥 (不常用)
filePermissions, directoryPermissions如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(不常用)

2.mirrors(镜像)

<mirrors>
    <mirror>
        <id>planetmirror.com</id>
        <name>PlanetMirror Australia</name>
        <url>;/url>
        <mirrorof>central</mirrorof>
    </url></mirror>
</mirrors>
Copy after login

设置一个中央仓库的镜像,看仓库分类,也是远程仓库的一种配置方式。

3.profiles(构建环境)
这个可能比较难理解,maven权威指南一书中这样说:

  Profile能让你为一个特殊的环境自定义一个特殊的构建;
  构建环境的两个例子是产品环境和开发环境。当你在开发环境中工作时,你的系统可能被配置成访问运行在你本机的开发数据库实例,而在产品环境中,你的系统被配置成从产品数据库读取数据。Maven能让你定义任意数量的构建环境(构建profile),这些定义可以覆盖pom.xml中的任何配置。

简单理解就是你可以先profile中先构件好项目运行的环境,比如预设了A环境实在开发中使用,而实际上线是B环境,那么在上线的时候我们不需要一个个修改pom.xml中的配置,只需要激活改profile即可。

4.activation(激活构建环境 )

<activation>
    <activebydefault>false</activebydefault>
    <jdk>1.5</jdk>
    <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
    </os>
    <property>
        <name>mavenVersion</name>
        <value>2.0.3</value>
    </property>
</activation>
Copy after login

指定profile中配置的环境在什么时候开始生效

5.activeProfiles(激活了的profile)

<activeprofiles>
<activeprofile>env-test</activeprofile>
</activeprofiles>
Copy after login

在Use nexus to build a LAN private server最后的一个标签,表示env-test这个profile已被激活

The above is the detailed content of Use nexus to build a LAN private server. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use EasyTier remote networking How to use EasyTier remote networking Jun 19, 2024 am 10:14 AM

EasyTier is an open source, free, decentralized intranet penetration remote networking tool. It is an easy-to-use and feature-rich remote networking solution, suitable for remote office collaboration, game connection and other scenarios. The following is a brief introduction to how to use EasyTier remote networking. Download the easytier-gui program and install it. Download address: https://github.com/EasyTier/EasyTier Just set it up as shown above on the computer that needs to be networked. Virtual IPv4 address: required. For example, computer A is 10.10.10.1, B is 10.10.10.2, and C is 10.10.10.3. It cannot be repeated. (Such IP segments are available: 10.

Java Maven build tool advancement: optimizing compilation speed and dependency management Java Maven build tool advancement: optimizing compilation speed and dependency management Apr 17, 2024 pm 06:42 PM

Optimize Maven build tools: Optimize compilation speed: Take advantage of parallel compilation and incremental compilation. Optimize dependencies: Analyze dependency trees and use BOM (bill of materials) to manage transitive dependencies. Practical case: illustrate optimizing compilation speed and dependency management through examples.

Avoid common mistakes in Maven environment configuration: Solve configuration problems Avoid common mistakes in Maven environment configuration: Solve configuration problems Feb 19, 2024 pm 04:56 PM

Maven is a Java project management and build tool that is widely used in the development of Java projects. In the process of using Maven to build projects, you often encounter some common environment configuration problems. This article will answer these common questions and provide specific code examples to help readers avoid common configuration errors. 1. Maven environment variables are incorrectly configured. Problem description: When using Maven, if the environment variables are incorrectly configured, Maven may not work properly. Solution: Make sure

Guide to setting up Maven local libraries: efficiently manage project dependencies Guide to setting up Maven local libraries: efficiently manage project dependencies Feb 19, 2024 am 11:47 AM

Maven local warehouse configuration guide: Easily manage project dependencies. With the development of software development, project dependency package management has become more and more important. As an excellent build tool and dependency management tool, Maven plays a vital role in the project development process. Maven will download project dependencies from the central warehouse by default, but sometimes we need to save some specific dependency packages to the local warehouse for offline use or to avoid network instability. This article will introduce how to configure Maven local warehouse for easy management

Basic tutorial: Create a Maven project using IDEA Basic tutorial: Create a Maven project using IDEA Feb 19, 2024 pm 04:43 PM

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA

Complete guide to install Maven on CentOS7 Complete guide to install Maven on CentOS7 Feb 20, 2024 am 10:57 AM

Detailed tutorial on how to install Maven under CentOS7 Maven is a popular project management tool developed by the Apache Software Foundation. It is mainly used to manage the construction, dependency management and project information management of Java projects. This article will detail the steps on how to install Maven in CentOS7 system, as well as specific code examples. Step 1: Update the system Before installing Maven, you first need to ensure that the system is up to date. Open a terminal and run the following command to update the system: sudoy

Detailed explanation of Maven Alibaba Cloud image configuration Detailed explanation of Maven Alibaba Cloud image configuration Feb 21, 2024 pm 10:12 PM

Detailed explanation of Maven Alibaba Cloud image configuration Maven is a Java project management tool. By configuring Maven, you can easily download dependent libraries and build projects. The Alibaba Cloud image can speed up Maven's download speed and improve project construction efficiency. This article will introduce in detail how to configure Alibaba Cloud mirroring and provide specific code examples. What is Alibaba Cloud Image? Alibaba Cloud Mirror is the Maven mirror service provided by Alibaba Cloud. By using Alibaba Cloud Mirror, you can greatly speed up the downloading of Maven dependency libraries. Alibaba Cloud Mirror

How to disable test cases in Maven? How to disable test cases in Maven? Feb 26, 2024 am 09:57 AM

Maven is an open source project management tool that is commonly used for tasks such as construction, dependency management, and document release of Java projects. When using Maven for project build, sometimes we want to ignore the testing phase when executing commands such as mvnpackage, which will improve the build speed in some cases, especially when a prototype or test environment needs to be built quickly. This article will detail how to ignore the testing phase in Maven, with specific code examples. Why you should ignore testing During project development, it is often

See all articles