A simple introduction

Foreword: Common Maven repositories are central (globally shared), private (internally shared), and local (privately owned). Similar code hosting is probably GitHub(global code hosting) and GITee (domestic version of the code hosting) and Gitlab(company private code hosting), all general companies to build internal is often internal code hosting (Gitlab) and internal JAR package hosting (Nexus private server), the main demonstration here is nexus private server The main purpose of maven is to learn and simulate the process of uploading jar packages to the company.

Halfway encountered difficulties combined with Baidu, here to provide some solutions for reference only (blog.csdn.net/qq_34531925…)

Private server construction

Install nexus private server software

Both the local JDK and Maven are installed

First installation or natural need to set up the server software, then the nexus software download address: www.sonatype.org/nexus/go

For example, nexus 3.28.1-01 will be released on October 24, 2020

Then fill in your email (such as your QQ email)

Download the software

After downloading it, unzip it to the installation folder you want (for example, D:\Asoftware\package\ Nexus) and configure the environment variables

CMD start nexus /run

Waiting for startup success

Test whether local access is working properly

First visit http://localhost:8081/

Click the upper right corner to log in (the pop-up box indicates that the user name is admin and the password is in the corresponding folder, please fill in as required)

The following steps prompt you can reset the password (I directly used to change the password to admin, so that a little more convenient) note to remember it after the modification oh, the original password file will be automatically deleted after you change the normal login interface

Exe /install nexus (Could not open SCManager) to configure nexus as a system service. Check the Windows Task Manager to make sure (stopped, continue to the next step).

Nexus Software catalog introduction

As is shown in

The installation directory provides an overview

Bin Contains the startup script of the Nexus and related configurations etc Jetty and Karaf configuration files jre JRE environment lib Java rack package library Public Resources required for running nexus applications locally System All plug-ins and components of the Nexus application License. TXT and notica. TXT Copyright notices and legal detailsCopy the code

Data document catalog is briefly introduced

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Elasticsearch: / / elasticSearch: / / elasticSearch: / / Log files are generated every day. You can periodically delete the old log file TMP/the directory used to store temporary filesCopy the code

Basic Configuration of Nexus

Example Change the software port number

Nexus configuration of maven repository

createBlob Strores(optional)

Before creating a Repository, you need to specify a directory for storing files for unified management. Before creating a Repository, you need to specify a directory for storing files for unified management. This step is not necessary

configurationProxy RepositoryThe agent warehouse

Create a Proxy Repository. After creating a Repository, the jar files will be stored in the specified directory.

 

After the page is created, there are three boxes on the page that are required:

The general selection of Mixed(including SNAPSHOT and RELEASE versions) in the following image can also be based on your needs

createhosted repositoryThe host warehouse

Is the private server JAR package in the computer that location (the company must be the cloud server, here simulation on the machine)

There are three ways to use Hosted: Releases, Snapshot, and Mixed(similar to above)

  • Releases: Typically Releases a Jar package
  • Snapshot: indicates an unreleased version
  • I’m too Mixed

If you can’t download the jar package on the private server, you can download the jar package directly, and configure the image like Maven’s setting.

Here are a few recommended remote warehouses:

  • Jboss maven central warehouse address: repository.jboss.com/maven2/
  • Ali cloud maven central warehouse address: maven.aliyun.com/nexus/conte…
  • Apache maven central warehouse address: repo.maven.apache.org/maven2/

 

 

creategroup repositoryThe warehouse group

It’s like having a warehouse as a spare and using it sequentially

Explain it in generalWhy do you care about order

The official document recommends: It is recommended practice to place hosted repositories higher in the list than proxy repositories. For proxy repositories, the repository manager needs to check the remote repository which will incur more overhead than a hosted repository lookup.

It is desirable to place hosted Repositories before Proxy repositories, because these repositories and proxies can be contained in a group. And a whole group is used as a public, an interface to others.

So when looking for jar packages, if the proxy repository comes first, it is to look for the JAR remotely first, rather than looking for the jar from the host repository (local repository) first

The test enabled the Maven project to use Nexus private server

Idea Sets Nexus to the mirror address

Maven setting.xml file and your own project pop.xml file:

  • settting.xmlFiles are global variables on the local computer; whilepom.xmlFiles are local variables.
  • pom.xmlFiles are a priority for the project. However,pom.xmlIf the file does not specify where to download the JAR from, then there is no configurationMirror addressThen, of course, only to followsettting.xmlTo find the address defined in

http://localhost:9081/repository/myself_group/

Configure the Maven configuration file setting.xml

<! - custom maven local warehouse address (note that the direction of the diagonal) - > < localRepository > D: / Aworkspace/mavennexus/nexusrepo < / localRepository > <! Nexus server --> <server> <id> Nexus </id> <username>admin</username> <password>admin</password> </server> <server> <id>nexus-releases</id> <username>admin</username> <password>admin</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin</password> </server> <! Set mirrorOf (central) to 'id' and 'name'; <mirrors> <id> Nexus </id> <name> Nexus repository</name> <url>http://localhost:9081/repository/myself_group/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>Copy the code

 

Idea set up maven test

View the URL of the POM configuration

Pom (note the content source configured inside) note that to package the source code need to add plug-ins, otherwise the source code will appear when downloading

Idea failed to download nexus private server jar package source code. So here according to the need, generally choose to be released source code, otherwise the world download your JAR package failed, read the source code is not comfortable

<distributionManagement> <repository> <id>nexus-Release</id> <name>Nexus Release Repository</name> <url>http://localhost:9081/nexus/content/repositories/Release/</url> </repository> <snapshotRepository> <id>nexus-SNAPSHOT</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:9081/nexus/content/repositories/SNAPSHOT/</url> </snapshotRepository> </distributionManagement> <build> <plugins> <! To put the source code on, Maven --> <plugin> <artifactId> Maven-source-plugin </artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals>  </execution> </executions> </plugin> </plugins> </build>Copy the code

Add, delete, change and check (CRUD) of private server

Upload jar to Nexus Private server – New

To the configuration of the private server warehouse check

Check again on the Private server console that you can search zXX-Nexus by artifactId (artifactId for my maven test)

Here, basically completed the construction of the all the servers configuration and maven project, implemented a complete private servers warehouse (pull private servers jar shows: no, because nothing is different, and before the maven logic is same, only the local can’t find the jar package, is directly to the central warehouse before download, but first maven go to private servers to see now There is no need to go to the central repository, so this is done automatically by Maven after configuring the Settings file.

Nexus Private server view JAR details – find

Idea maven project can be downloaded from nexus Private server jar

Simply add the corresponding JAR to pom.xml as a table

Test using

Try to download the jar source code (note that this is the source code package configured in the package, is that the POM configured plug-in only line, otherwise can not download the JAR source code as private server authorization or other where configuration is incorrect, in fact, of course, again reminder to configure the correct ha setting file).

 

Nexus Private jar package deletion – delete

After entering the details in the previous step, click the Browse SNAPSHOT(s) and enter

Nexus private jar package modification

In fact, when uploading the upgrade version number, there is no so-called modification jar package, to modify GAV coordinates, directly upload on the line, if the previous coordinates are changed, directly delete the original coordinates, the new upload can be, this is just for obsessive-compulsive complete add, delete, change and check the integrity

Handle the details of uploading jar packages to private servers

Upgrade jar package version and upload to private server

Modified the code, must be the new version (even if it’s just add a comment, a habit), this process of conflict there is no jars. (only distributed development do not match the jar version users can lead to class jar package, interface code, such as this is not the maven private servers pot), in this case, need to choose after discussion Select the JAR package of the corresponding version