Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

First acquaintance with Maven and nexus, and nexus installation

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, understand Maven

Excellent build tools

Through a simple command, you can complete a series of processes, such as cleaning, compiling, testing, packaging, deployment, and so on. At the same time, Maven can use the same command across platforms, whether on Windows, Linux, or Mac.

two。 Rely on management tools

The third-party open source class libraries that the project depends on can be introduced into the project in a dependent way. Instead of downloading a third-party jar first, and then adding it to the project. Thus, it can better solve the problems of increasing dependence, inconsistent version, version conflict, bloated dependence and so on.

How exactly is it realized? Maven locates each component accurately through the coordinate system, that is, through the coordinates to find the corresponding java class library.

3. Project information management tool

Able to manage project description, developer list, version control system address, license and other scattered project information. In addition to direct project information, through Maven automatically generated sites, as well as some existing plug-ins, you can also easily get project documents, test reports, static analysis reports, source code versions, log reports and other very valuable project information.

II. Maven and Nexus

The problem starts with the second use of Maven, which relies on management to introduce jar into the project by specifying coordinates in the Pom. So what kind of process does this process have to go through? Where can I find jar? Where do I put the downloaded jar?

If you take this problem down, you will know the relationship between nexus and maven.

From × × to jar? Where is the jar used in the project stored? This leads to the concept of warehouse, through which maven uniformly manages various components. Maven warehouses are divided into local warehouses and remote warehouses.

When Maven looks for a component according to its coordinates, it will first check the local warehouse and use it directly if it exists in the local warehouse; if this component does not exist in the local warehouse, or if you need to check whether there is an updated version of the component, Maven will go to the remote warehouse to find the required component and download it to the local warehouse for re-use.

Project = > local warehouse = > remote warehouse

Nexus is a kind of remote warehouse, according to the introduction of the previous paragraph, we already know the role of remote warehouse. In the remote warehouse, the default is the central warehouse, and the central warehouse is the remote warehouse that comes with the Maven core. Then just use the central warehouse, why do we install Nexus?

From the perspective of the actual development of the project:

1. Some artifacts that cannot be downloaded from external repositories, such as internal projects, can also be deployed to private servers for use by other dependent projects.

In order to save bandwidth and time, set up a private warehouse server in the local area network and use it to represent all external remote repositories. When the local Maven project needs to download components, first go to the private server request, if not, then go to the remote warehouse to request, after downloading the components from the remote warehouse, cache the components on the private server. In this way, there is no Internet link for the time being, because the private server has already cached a large number of components, the whole project can still be used normally. At the same time, it also reduces the load of the central warehouse.

Therefore, Nexus is only a kind of private service.

III. Nexus installation

1. Environment: centos7

Version:

Jdk:jdk-7u45-linux-x64.rpm

Nexus:nexus-2.14.2-01-bundle.tar.gz

Maven:apache-maven-3.3.9-bin.tar.gz

two。 Install jdk,maven environment configuration

Configuration:

JAVA_HOME=/usr/java/jdk1.7.0_45JRE_HOME=/usr/java/jdk1.7.0_45/jrePATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$M2_HOME/binCLASSPATH=$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarM2_HOME=/data/apache-maven-3.3.9

Export JAVA_HOME JRE_HOME PATH CLASSPATH M2_HOME

Source / etc/profile

Version View:

Java version: java-version

Maven version: mvn-- version

3. Install, configure nexus

Extract the downloaded nexus-2.14.2-01-bundle.tar.gz package to / data

Edit the nexus script file

Cd / data/nexus/nexus-2.14.2-01/bin

Cat nexusNEXUS_HOME= ".." # # nexus installation directory / data/nexus/nexus-2.14.2-01RUN_AS_USER=root # # launch nexus user

There are two files:

Nexus-2.14.2-01:nexus service

Sonatype-work: private library directory

Start the service with nexus settings:

Sh / data/nexus/nexus-2.14.2-01/bin/nexus

4. Visit nexus

Log in to http://IP:8081/nexus/

Default username and password: admin admin123

4. Maven command

Maven builds the java project, and the structure and content of the Maven project are based on pom.xml. The common packaging commands are mvn package, mvn install, and mvn deploy. Package to generate a jar package or war. But there is a difference between the three.

Mvn clean package: seven stages of clean, resources, compile, testResources, testCompile, test and jar were carried out in turn. Mvn clean install: eight stages such as clean, resources, compile, testResources, testCompile, test, jar and install were carried out in turn. Mvn clean deploy: nine stages such as clean, resources, compile, testResources, testCompile, test, jar, install and deploy were carried out in turn.

The clean command is to clean up the target target file under the build project, that is, to delete the target file directory under the project. After the project code is modified, you need to use clean to clear the target and regenerate the target.

The package command completes the project compilation, unit test, and packaging functions, but the finished jar package is not deployed to the local maven repository and remote private server.

The install command completes the functions of project compilation, unit test and packaging, and deploys the finished jar package to the local maven warehouse, but not to the remote private server warehouse.

The deploy command completes the functions of project compilation, unit test and packaging, and deploys the finished jar package to the local maven warehouse, as well as to the remote private server warehouse.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report