Nexus private server setup

About the author

  • The authors introduce

🍓 blog home page: author’s home page 🍓 Introduction: JAVA quality creator 🥇, a junior student 🎓, participated in various provincial and national competitions during school, and won a series of honors


1, the preface

Nexus can do Maven private server. Private server is not the core concept of Maven, it is just a special Maven repository derived from Maven. There are three types of Maven repository management software that can be used to help you set up private servers:

Archiva from the Apache Foundation, Artifacotory from JFrog, and Nexus from Sonatype. Archiva is open source, as are the cores of Artifacotory and Nexus.

Nexus is an “out of the box” system that does not require a database, uses a file system plus Lucene to organize data, and supports WebDAV and LDAP secure authentication. Nexus also offers powerful warehouse management, component search, reST-based, reST-friendly UI is an EXTJS REST client that uses less memory and is based on a simple file system rather than a database. Nexus greatly simplifies maintenance of local internal warehouses and access to external warehouses. In addition, Nexus can also proxy remote warehouses while maintaining local warehouses, to reduce the load of the central warehouse, save Internet bandwidth and time. For this Nexus, install version 3.x

2. What is private server?

Private server refers to a private server, which is assumed to be a special remote repository on a LOCAL area network. The purpose is to proxy remote repository and deploy third party builds. With private servers, when Maven needs to download components, it directly requests private servers and downloads them to the local repository. Otherwise, the server requests the external remote repository to download the component to the server and provide it to the local repository for download.

👦👦👦 must have some friends asking again

3. What is Nexus?

Nexus is a powerful Maven repository manager that greatly simplifies maintenance of local internal repositories and access to external repositories

Nexus is an out-of-the-box system that doesn’t need a database. It uses a file system plus Lucene to organize data

Nexus uses ExtJS for interface development and Restlet to provide complete REST APIs that are integrated with IDEA and Eclipse

Nexus supports WebDAV and LDAP secure authentication

Nexus provides powerful warehouse management, component search, reST-based, reST-friendly UI is an EXTJS REST client that takes up less memory and is based on a simple file system rather than a database

4. Why build Nexus Private server?

  • Intranet access, saving Internet bandwidth.
  • Once downloaded from the Internet, all Intranet users can download only the private server cache, speeding up Maven project construction.
  • Allows private libraries to be uploaded and downloaded without external access for greater security.
  • Reduce external network factors and provide stability for project construction.
  • Facilitate dependency references to internal project services without requiring complete source code for other projects.
  • Facilitate the maintenance of common components
  • Improve work efficiency

👨💻 With these basic concepts in mind, it’s time to get into the real world

5. Nexus Download

We chose to use Nexus, the most popular open source Maven repository management software, to quickly build Maven private server

The factory director provides you with two download methods:

The Nexus of the website www.sonatype.com/products/re…

Baidu network backup link: pan.baidu.com/s/1axGwnPzZ… Extraction code: WPZR

CSDN resource download

In the process of submission

6. Use Nexus to build a private server

1) No installation, download down, decompress directly to run.

2) Configure environment variables

The purpose of this is to enable startup in the global CMD window

3) run

Windows +R – Enter CMD – Nexus /run

If this box appears, the startup is successful 😃😃😃.

4) test

Enter http://localhost:8081/ in the address bar of your browser

Note: the default port nexus\nexus-3.20.1-01\etc\nexus-default.properties can be modified

😎 solution: the password is wrong when landing private service

The old versionAccount admin Password Admin123 New version (recommended) Default UserName: The password for admin to log in to the system for the first time is randomly generated. Copy the password to the admin.password file

After you log in, a dialog box is displayed asking you to change the password. If you change the password as prompted, you can use your password to log in.

7, the use of private service

1) Repositories

  1. Hosted: A local repository (also called a hosted repository), where typically we will deploy our own components to this type of repository or to a third-party package (e.g. Oracel’s).
  2. Proxy: Proxy repositories, which are used to proxy remote public repositories, such as maven central repositories.
  3. Group: repository group used to merge multiple Hosted/Proxy repositories, which maven is typically configured to rely on
  4. Maven-central: Maven central library, drawn by default from repo1.maven.org/maven2/ ja…
  5. Maven-releases: Releases the PRIVATE library JAR
  6. Maven-snapshots: snapshots of private libraries (debug versions) JAR
  7. Maven-public: repository group, which combines the preceding three repositories to provide external services. Maven-public is used in the local Maven basic configuration settings.xml.

Hosted means host, and Releases it in three ways: Releases, Snapshot, and Mixed

Releases: generally a released Jar package with the Snapshot version that is not released Mixed

When PC accesses the central repository, it will download it to Nexus repository through proxy, and then download it to PC locally from Nexus repository. Such advantages as long as one of them from the central library down, we are from the Nexus private server down, private server is generally deployed on the Intranet, so greatly saving broadband.

Remote Storage: specifies the address of the agent. Maven: specifies the address of the agent. repo1.maven.org/maven2/ Blob Store: specifies the directory where the agent download package is stored

2) Create Proxy Repository.

Nexus aliyun
http://maven.aliyun.com/nexus/content/groups/public
Copy the code

3) Create a custom warehouse

4) Customize the group resource library

8. Use Nexus private server in Maven project

1) Create roles

Multiple users can be assigned rights to a role only after a role has been created

2) Create a user

3) Maven setting.xml file configuration

Define the Maven repository for jar downloads, and define the deployment server. But certain configurations such as username and password are saved in settings.xml in the build server.

Id: the ID of the server, which matches the id of the distributionManagement library. Username, password: specifies the username and password used to log in to the server privateKey, passphrase: specifies the private key, and passphrase filePermissions, directoryPermissions: When a library file or directory is created, you need permission to access it. See Unix file licenses, such as 664 and 775 mirrors: mirrors of a library that can be used to add other libraries. Mirror is an interceptor that intercepts Maven requests for remote Repository and redirects the requested remote Repository address to the mirror’s configured address. Url: URL of the mirror mirrorOf: ID of the service to which the mirror points

Configuration of the Servers tag

<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.
     |
     -->
    <! Create a custom repository address for Maven.
    <localRepository>E:/enviroment/repository</localRepository>
    <server>
      <id>release</id>
      <username>admin</username>
      <password>123456</password>	<! The password here is the password you changed before -->
    </server>
    
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>123456</password>	<! The password here is the password you changed before -->
    </server>
</servers>
Copy the code

Configuration of the Profiles TAB

<profiles>
	<profile>
      <id>default_profile</id>
      <repositories>
        <! -- Contains information needed to connect to the remote repository -->
        <repository>
          <! -- Remote repository unique identifier -->
          <id>nexus</id>
          <! -- Remote repository name -->
          <name>maven-public</name>
          <! How to download a release from a remote repository
          <releases>
            <! --true or false indicates whether the repository is open for downloading certain types of artifacts (release, snapshot). -->
            <enabled>true</enabled>
            <! This element specifies how often updates occur. Maven compares local POM timestamps with remote POM timestamps. The options are: always (always), daily (default, daily), interval: X (where X is a time interval in minutes), or never (never). -->
            <updatePolicy>never</updatePolicy>
            <! What to do when Maven validators fail to validate files -ignore, fail, or WARN. -->
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <! How to handle the download of snapshot versions in remote repositories. With releases and snapshots, the POM can take different policies for each type of artifact in a separate repository. For example, someone might decide to turn on support for snapshot version downloads only for development purposes. See the repositories -- > / repository/releases elements
          <snapshots>
            <! --true or false indicates whether the repository is open for downloading certain types of artifacts (release, snapshot). -->
            <enabled>true</enabled>
            <! This element specifies how often updates occur. Maven compares local POM timestamps with remote POM timestamps. The options are: always (always), daily (default, daily), interval: X (where X is a time interval in minutes), or never (never). -->
            <updatePolicy>always</updatePolicy>
            <! What to do when Maven validators fail to validate files -ignore, fail, or WARN. -->
            <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          <! Protocol ://hostname/path -->
          <url>http://localhost:8081/repository/maven-public/</url>
          <! Warehouse layout type used to locate and sort artifacts - can be default or Legacy. Maven 2 provides a default layout for its repository; However, Maven 1.x has a different layout. We can use this element to specify whether the layout is default or Legacy. -->
          <layout>default</layout>
        </repository>
      </repositories>
      
      <pluginRepositories>  
        <pluginRepository>  
          <id>maven-net-cn</id>  
          <name>Maven China Mirror</name>  
          <url>http://localhost:8081/repository/maven-public/</url>  
          <releases>  
            <enabled>true</enabled>  
          </releases>  
          <snapshots>  
            <enabled>true</enabled>  
          </snapshots>      
        </pluginRepository>  
      </pluginRepositories> 
  
    </profile>
</profiles>
Copy the code

4) The deployment repository is defined by the distributionManagement element in the POM.

<distributionManagement>
    <repository>
        <id>maven-releases</id>
        <name>Nexus Release Repository</name>
        <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>maven-snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
Copy the code

Then run the MVN clean deploy command

Here Nexus private server is configured! Thank you for watching.

I hope this article is helpful to your study, and I hope you can support the factory director and leave your love 💕 and like 👍!

After the language

The original intention of the director to write blog is very simple, I hope everyone in the process of learning less detours, learn more things, to their own help to leave your praise 👍 or pay attention to ➕ are the biggest support for me, your attention and praise to the director every day more power.

If you don’t understand one part of the article, you can reply to me in the comment section. Let’s discuss, learn and progress together!

Wechat (Z613500) or QQ (1016942589) for detailed communication.