Maven tutorial (9) - Maven coordinates Detailed

Original Address: https://blog.csdn.net/liupeifeng3514/article/details/79544532

The role of a core of Maven is to manage project dependencies, we need to introduce a variety of jar packs. In order to automate the parsing any Java component, Maven Jar package must be these or other resources to uniquely identify, which is dependent on the basic management of the project, which is what we want to say coordinates. Including our own development projects, but also to be uniquely identified by coordinates, so as to be dependent only refer to other projects.

1, what is Maven coordinates

About coordinates (Coordinate), it should be the most familiar with the mathematical coordinates of the bar, not particularly deep impression on me, that's a little mathematics called plane geometry. In a plane coordinate system with the x-axis and y-axis, the x-axis is horizontal, the y-axis is vertical, the coordinates (x, y) represents the point y from the x-axis, y-axis is the distance x of the point, any can uniquely identify a coordinate point of the plane.

In real life, we can address as a kind of coordinates. Different provinces, different city, different areas, different streets and a series of information that identifies each with a different address. Often eat takeout in Shenzhen people should have the experience, food delivery brother will be based on your address will fill in the takeaway for you, and the address you fill it identifies a unique address.

Coordinate like the same ID card every Java component. Maven world is to have a lot of Java components, possibly jar, you might be war, it could be something else. If there is no concept of Maven coordinates, we are unable to distinguish between these members, so we have to uniquely identify each component. Or else, like the traditional manual way, you need to go to spring spring spring downloaded packages, you need to download the mysql went mysql mysql package, there is no uniform standard, how can automation to rely on these components.

Maven gave us develop a set of rules that is uniquely identified using coordinates. Maven coordinate elements include groupId, artifactId, version, packaging, classfier. As long as we provide the correct coordinates of the element, Maven will be able to find the corresponding components, first go to your local repository to find, if not go to a remote repository download. If no remote repository, by default from the central warehouse address ( http://repo1.maven.org/maven2 ) download component, the central repository contains the world's most popular open source project members, but not necessarily all of the components have , I encountered a problem can not find the oracle database jar package in the previous development, do not know whether remains the same.

When our own development projects, but also to give our definition coordinate the project, which is a mandatory requirement, the only way the project can reference other components of the project.

2, the coordinates of the detailed description

Maven coordinates through groupId, artifactId, version, packaging, classfier these elements to define, let's look at an example:

 

 

We generally only need to use in the normal development of the necessary elements of several good, some elements unnecessary often do not need, let's take a look at what each element represents, in front also has a simple mention of.

groupId: define the actual project is currently Maven project belongs. First, Maven project and the actual project is not necessarily one to one relationship. For example SpringFrameWork the actual item, which corresponds Maven project there will be many, such as spring-core, spring-context like. This is because the concept in Maven modules, therefore, a real project tend to be divided into many modules. Secondly, groupId corresponding item should not be affiliated organization or company. The reason is simple, there are many practical items under one organization, if groupId to define only the organizational level, and we shall see later, artifactId can only be defined Maven project (module), then the actual project this level will be difficult to define. Finally, similar expressions groupId representation of the Java package name, usually one correspondence with the reverse domain name. The example above, groupId as junit, is not feeling very special, this is possible, because the world on such a junit, it is also not a lot of branches.

artifactId: This element defines a Maven project (module) current actual project, the recommended practice is to use the actual project name as a prefix of artifactId. Examples of such a junit, junit is the actual name of the project, easy and intuitive. By default, maven generated artifacts, will artifactId as the file header, such as junit-3.8.1.jar, actual project name as a prefix, you can easily find members of an item from a local warehouse.

version: This element defines the version of the component, the above embodiment junit version 3.8.1 is, you can instead version 4.0 4.0 junit indication.

packaging: the definition of a packed fashion Maven project, use the components of what the package. First, a packaging typically corresponds to the generated file extension member, as no Packaging embodiment, the default is jar package, the final file named junit-3.8.1.jar. And the like can also be packaged into war.

classifier: This element is used to help define a build some output attachments. Corresponding to the attachment member and the main member, the main member in the above embodiment is junit-3.8.1.jar, the program may also be generated as junit-3.8.1-javadoc.jar, junit-3.8.1-sources by a number of plug-ins. jar, so that the attachment member will have their own unique set of coordinates.

The five elements, groupId, artifactId, version must be defined, and optional Packaging (JAR default), and can not be defined directly classfier, it requires a combination of plug-ins.

We can find a name by the value of this component is composed of several elements, junit-3.8.1.jar, compare themselves to look at, not only that, the layout of Maven repository is also based on Maven coordinates, we can see so whether local warehouse layout.

After understanding the Maven coordinates, we can begin to learn of the Maven dependency management.

 

Guess you like

Origin www.cnblogs.com/dyh004/p/11579421.html