This article explains the use of Maven in Eclipse, which comes with a Maven plugin in some of the higher versions of Eclipse. So this is not going to explain how to install the plugin.
Next we create a Mavenfirst project
First, create a Mavenfirst project in Eclipse
First step: Create a MAVEN project
Step two: Choose to create a Java project-->next
Step three: Fill in the Gav
Fourth step: Click Finsh to complete the creation
Fifth step: Create a Mavenfirst.java
Package Com.zyh.maven.MavenFirst; Public class Mavenfirst { public string SayHello (string name) { return] Hello "+name; }}
Mavenfirst
Position:
Sixth step: Execute MAVEN commands using Eclipse's options
Attention:
The 6--9 here are all shortcuts.
9 test, equivalent to command line MVN test
8 installation, equivalent to the command line mvn install role: upload it to the local warehouse, see the above explained
7 related source code, this does not need to explain, usually we use other jar package also associated with the source code
6 Cleaning, mvn clean
5 maven bulid execute maven command, equivalent MVN
4 Maven Build 5 quick action
If not operated, same as 5
If the operation was done once, the last 5 command will be executed directly
If the action is multiple times, a selection box is provided
Seventh step: View the file structure when we execute MAVEN install
Note: If our example is a MAVEN Web project, publish the MAVEN Web project to Tomcat to run
Command: Tomcat:run
Accessed via the URL, and uploads the item to the local repository.
second, MAVEN coordinates2.1. What is coordinates
About coordinates (coordinate), we are most familiar with the mathematics of the coordinates, I am not particularly impressed, said the math major is called plane geometry. In a planar coordinate system, there are X-and Y-axes, the x-axis is the horizontal line, the y-axis is the vertical bar, and the coordinates (x, y) indicate that the point is the x-axis y and the y-axis is x, and any coordinate can uniquely identify a point in the plane.
In real life, we can consider an address as a coordinate. Different provinces, different cities, different districts, different streets, etc. a series of information identifies each of the different addresses. In Shenzhen often eat takeout people should have experience, delivery of the small brother will be based on the address you fill out to you, and you fill in the address to identify the only one address.
Coordinates are like each Java component's identity card. The world of Maven has a lot of Java artifacts, possibly jars, war, and possibly other things. If there is no concept of coordinates in MAVEN, we cannot differentiate these artifacts, so we have to uniquely identify each component.
Otherwise, like the traditional manual way, you need spring to spring to download the spring package, MySQL and mysql to download the MySQL package, there is no unified specification and how can be automated to rely on these components.
Maven gives us a set of rules that are uniquely identified using coordinates. maven's coordinate elements include GroupID, Artifactid, version, packaging, Classfier. As long as we provide the correct coordinate elements,maven will be able to find the corresponding components, first go to your local repository to find, no, then go to the remote repository download.
If you do not configure a remote repository, the widget is downloaded by default from the Central warehouse address (HTTP://REPO1.MAVEN.ORG/MAVEN2), which contains most of the most popular open source project artifacts in the world, but not necessarily all of them . I have encountered problems with the Oracle database jar package in my previous development and I don't know if this is still the case now.
When we develop our own projects, we also want to define coordinates for our projects, which is a mandatory requirement, so that other projects can reference the artifacts of the project.
2.2, the main composition of MAVEN coordinates
GroupId: Organizational identity (package name)
Artifactid: Project Name
Version: Current versions of the project
Packaging: How to Package a project, the most common jar and war Two kinds
Classifier: This element is used to help define some of the subordinate artifacts of the build output
Note: groupId, Artifactid, version, packaging must be defined, and classifier cannot be defined directly, because the subordinate artifacts are not generated directly by default, but are generated by the additional plug-in Help.
groupId : Defines the actual project that the current MAVEN project belongs to. First, the MAVEN project and the actual project do not necessarily have a one-off relationship. For example springframework this actual project, its corresponding MAVEN project will have many, such as Spring-core,spring-context and so on. This is due to the concept of modules in Maven, so a real project is often divided into modules.
Second, GroupID should not correspond to the organization or company to which the project belongs. The reason is very simple, there will be many actual projects under an organization, if GroupID is defined only at the organization level, and later we see that Artifactid can only define MAVEN projects (modules), then the actual project level will be difficult to define.
Finally, the GroupID is expressed in a similar manner to the Java package name, usually corresponding to the reverse one by one of the domain name. In the above example, GroupID is JUnit, is not feeling very special, this is also possible, because the world is such a junit, it does not have many branches.
Artifactid : This element defines a MAVEN project (module) in the current actual project, and the recommended practice is to use the actual project name as the prefix for the Artifactid. For example, the Junit,junit in the example above is the actual project name, convenient and intuitive.
By default, MAVEN-generated artifacts use Artifactid as the header of a file, such as Junit-3.8.1.jar, to make it easy to find artifacts from the local repository by using the actual project name as a prefix.
Version: This element defines the versions that use artifacts, as in the previous example JUnit is 3.8.1, and you can change to 4.0 to use the 4.0 version of JUnit.
Packaging : Defines the way in which MAVEN projects are packaged, and what packages are used by the artifacts. First, the packaging method is usually the same as the file extension of the generated artifact, as in the example above, the default is the jar package, and the final file name is Junit-3.8.1.jar. Packaging. It can also be packaged as a war and so on.
classifier: This element is used to help define some attachments to the build output. The subordinate component corresponds to the main component, as the main component in the previous example is Junit-3.8.1.jar, and the project may be generated by some plug-ins such as Junit-3.8.1-javadoc.jar,junit-3.8.1-sources.jar, Such a subordinate member has its own unique coordinate.
2.3. Get maven coordinates (get MAVEN's three key attribute values)
1) Use Site search (from central warehouse)
The first step: Baidu search key word "maven repository"
Step Two: Enter the keyword query to get the required content, determine the required version
Step three: Get coordinates
2) Use the local repository to get coordinates through eclipse
First step: Add the dependent pom.xml file, right-click
Step Two: Enter keywords to get coordinates.
MAVEN (iii) using MAVEN and maven coordinates in eclipse