Maven Practical Reading notes (6)

Source: Internet
Author: User
Tags jboss

Maven What are the coordinates and dependencies? How is the logical representation and physical representation of a component?

1.coordinates and dependencies are the logical representations of any component in the Maven world

2.file is the physical representation of Maven components

3,Maven through the warehouse to manage these files uniformly

So, what is the component?

1, any dependency, plug-in or project-built output, can be called a component

2, dependent Log4j-1.2.15.jar is a component

3, plugin Maven-compiler-plugin-2.0.2.jar is a component

4,account-email project after the completion of the output Account-email-1.0.0-snapshot.jar is also a component

5. Any one component has a set of coordinates uniquely identified

Traditional projects about jars problem with the package?

1.on a workstation, there may be more than 10 items

2, most of the projects may be used in log4j, a small part of the Spring Framework, there is another small part of the Struts2

3, many projects are duplicated jar, resulting in wasted disk space, difficult to manage, file replication and other operations will also reduce the build speed

4, traditional projects often have a lib/ directory, the contents of the lib/directory of various projects there is a large number of duplication

How to solve the above problem? What is Maven 's warehouse?

1, thanks to the coordinate mechanism, any Maven project using any one component is exactly the same way

2.based on this,maven can store all MAVEN project-shared artifacts in a single location , and this unified location is the warehouse

3.actual projects will no longer store their dependent files, they only need to declare these dependent coordinates

What is the layout of the warehouse?

1, any component has its unique coordinates, according to this coordinate can define its unique storage path in the warehouse, this is Maven 's warehouse layout way

2, for example log4j:log4j:1.2.15 this dependency, its corresponding warehouse path is Log4j/log4j/1.2.15/log4j-1.2.15.jar

3, the format is groupid/artifactid/version/artifactid-version.packaging

Maven classification of warehouses?

Maven warehouses are divided into two categories: local warehouses and remote warehouses

Maven What is the mechanism for finding artifacts?

when when Maven looks for a widget based on coordinates, it first looks at the local repository and uses it if the local repository exists, or if the local repository does not have this artifact, or if you need to see if there is an updated build,Maven will go to the remote repository to find it. After discovering the required artifacts, download them to the local repository and use them, and if the local repository and remote repository do not have the required build,Maven will error

Classification of remote warehouses?

1, the Central warehouse is The maven core comes from the remote warehouse, it contains the vast majority of open-source components, in the default configuration, when the local warehouse does not have the Maven required components, it will try to download from the Central warehouse

2, Private server is another special remote warehouse, in order to save bandwidth and time, should be in the local area network to assume a proprietary warehouse servers, with its proxy all external remote warehouse, internal projects can also be deployed to other projects to use

3, in addition to the central warehouse and private, there are many other public Remote Storage common java.net Maven Library

(http://download.java.net/maven/2/) and the JBoss Maven Library (http://repository.jboss.com/maven2) , etc.

Local Warehouse Introduction

1.the Maven project directory does not have directories such as lib/that are used to store dependent files, and when you perform compilation or testing, if you need to use dependent files, it always uses the local repository's dependent files based on coordinates

2,by default, whether Windows or Linux, each user in their own user directory has a path named,m2/repository/ 's Warehouse directory

3, sometimes want to modify the warehouse directory, you can edit ~/.m2/settings.xml, set the value of the localrepository element, for example:

<settings>

<localRepository>D:\maven\repository</localRepository>

</settins>

Remote Warehouse Introduction

1, remote warehouse can have multiple, local warehouse can have only one

2.when Maven cannot find the required artifacts from the local repository, the artifacts are downloaded from the remote repository to the local repository

Central Warehouse Introduction

1, the most original local warehouse is empty,maven must know at least one remote repository available to download to the required artifacts when executing the Maven command

2, the central warehouse is such a default remote repository,Maven installation files with the configuration of the Central warehouse

3.Use the Unzip tool to open the jar file $M 2_home/lib/maven-model-builder-3.0.jar ( in maven 2 ,the jar The file path is similar to M2_home/lib/maven-2.2.1-uber.jar), then access the path,org/apache/maven/model/pom-4.0.0.xml, You can see the following configuration:

<repositories>

<repository>

<id>central</id>

<name>maven Repository switchboard</name>

<url>http://repo1.maven.org/maven2</url>

<layout>default</layout>

<snapshots>

<enabled>false</enabled>

</snapshots>

</repository>

</repositories>

The above configuration is explained:

1. Thefile containing this configuration is the Super POM that all Maven projects will inherit

2. This configuration uses ID central to uniquely identify the centralized repository, with the name Maven Repository switchboard, using the default warehouse layout, The snapshots element, whose child element enabled has a value of false, indicating that the widget that does not download the snapshot version from the Central warehouse

Cow X in central warehouse the Place

1, the central warehouse covers the vast majority of the world's popular open source Java components, as well as source code, author information,SCM, information, license information, etc., every month here will accept the world 's Java Programmers have about 1 billion visits

2, the central warehouse covers more than one of the components of open source projects, in general, a simple Maven project requires a dependency component can be downloaded from the Central warehouse to

What is it?

server is a special remote warehouse, which is set up in the local Area Network warehouse service, Remote Storage agent on the WAN, for the LAN Maven users use

What is the process of using a.

when when maven needs to download a widget, it requests it from the server, and if the widget does not exist on it, it is downloaded from an external remote repository, cached on it, and then served as a maven download request

In addition, some builds that cannot be downloaded from an external repository can be uploaded to a local repository for everyone to use

What are the advantages of building a?

1, save their own external network bandwidth

2. Accelerate Maven build

3. Deploy third-party components

4, improve stability, enhance control

5, reduce the load of the central warehouse

Configuration POM using JBOSS Maven Warehouse

in many cases, the default central warehouse does not meet the requirements of the project, and the artifacts that may be required for the project exist in another remote repository, such as JBoss Maven Warehouse

<project>

...

<repositories>

<repository>

<id>jboss</id>

<name>jboss repository</name>

<url>http://repository.jboss.com/maven2/</url>

<releases>

<enable>true</enable>

</releases>

<snapshots>

<enabled>false</enable>

</snapshots>

<layout>default</layout>

</repository>

</repositories>

...

</Project>

For the above configuration instructions:

1 . Under the repositories element, one or more remote warehouses can be declared using the repository child element. In this example, a warehouse with thename JBoss Repository is declared.

2, the ID of any one warehouse declaration must be unique, especially to notethat Maven 's own central warehouse uses the same ID, if other warehouse claims also use the ID, the configuration of the central repository will be overwritten

3, the URL in this configuration points to the address of the warehouse, in general, the address is based on the HTTP protocol,Maven users can open the warehouse address browsing widget in the browser

4, the configuration of important releases and snapshots elements, the enabled value of releases in this configuration is true, which means to turn on release version download support for JBoss Repository, while snapshots 's enabled value is false for download support toturn off the snapshot version of the JBoss repository , so Maven will only download the release artifacts from the JBoss repository in this configuration , without downloading the snapshot version of the widget

releases and snapshots Two additional sub-elements under updatepolicy and checksumpolicy

You may encounter a configuration such as the following:

<snapshots>

<enable>true</enable>

<updatePolicy>daily</updatePolicy>

<checksumPolicy>ignore</checksumPolicy>

</snapshots>

about updatepolicy the configuration

The element Updatepolicy is used to configure how often maven checks for updates from the remote repository, and the default value is daily, which means that Maven checks every day

other available values include:never-never check for updates;always-check updates for each widget;interval:x-Every x Group Check for Updates (X is any integer)

about checksumpolicy the configuration

The Checksumpolicy element is the policy used to configure Maven inspection checks and files. When the artifacts are deployed to the MAVEN repository, the corresponding checksum files are deployedat the same time, and Maven validates the checksum file when the component is downloaded

So what if the checksum fails?

when the value of Checksumpolicy is the default warn ,Maven outputs a warning message when the build is executed, and other available values include : Fail-maven Build failed with checksum error;Ignore----causes Maven to ignore checksum errors completely


Maven Practical Reading notes (6)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.