1.Maven Download and Installation:
This section is very simple, see the first part of my other blog post: http://6216083.blog.51cto.com/6206083/1813871
2.Maven building projects in Eclipse:
2.1 Replace the IDE's default maven plugin:
Now the mainstream Java development IDE, such as Eclipse, NetBeans, STS, and so on, will bring the Maven plugin, so we need to replace this "default Maven plugin" with the maven we installed in the previous step.
Open Eclipse, select Window-to-Preferences, and in the dialog box that appears, find Maven--and installations, and you'll see the Maven plugin with the eclipse default. As shown in the following:
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/9C/wKioL1ep9R3AD8uaAACXwY6EhJw469.png-wh_500x0-wm_3 -wmp_4-s_2760254219.png "title=" Eclipse built-in maven001.png "alt=" Wkiol1ep9r3ad8uaaacxwy6ehjw469.png-wh_50 "/>
Use Add to find our installed Maven directory (equivalent to the environment variable $m2_home) and add on it.
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/9C/wKiom1ep9deDcjMbAABnCNi4lQo750.png-wh_500x0-wm_3 -wmp_4-s_1877478925.png "title=" Eclipse built-in maven002.png "alt=" Wkiom1ep9dedcjmbaabncni4lqo750.png-wh_50 "/>
After adding, change the default maven to the external maven that we added last step.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/9C/wKioL1ep9h_hX4K5AACZgJSl8Y4094.png-wh_500x0-wm_3 -wmp_4-s_2547425982.png "title=" 003.png "alt=" Wkiol1ep9h_hx4k5aaczgjsl8y4094.png-wh_50 "/>
After that, modify the configuration of the configuration file settings.xml. Select Maven-to-user Settings to replace the settings.xml file with $m2_home/conf/settings.xml, including global Settings and user Settings, such as:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/85/9C/wKioL1ep91DivwFSAACitNjSOcc529.png-wh_500x0-wm_3 -wmp_4-s_3408156735.png "title=" 004.png "alt=" Wkiol1ep91divwfsaacitnjsocc529.png-wh_50 "/>
, the bottom of the "local Repository" is Maven's local repository. MAVEN's local repository will store some jar packages; Typically, a "company Repository" (a popular Nexus build) will be created in the company, and the MAVEN local repository will download some jar packages, dependencies, etc. from the company's warehouse. The company's warehouses are downloaded from the MAVEN central warehouse.
Of course, if we don't have a company repository, we can download it directly from MAVEN's central repository. The above relationship can be referred to:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/9C/wKioL1ep-WPzp13LAACXf6GtZSM854.png-wh_500x0-wm_3 -wmp_4-s_170955946.png "title=" 005.png "alt=" Wkiol1ep-wpzp13laacxf6gtzsm854.png-wh_50 "/>
2.2 Building a simple MAVEN project:
To create a new MAVEN project:
File--and New--Maven Project:
(1) using the default storage location, direct next;
(2) Choose which type of MAVEN project to build:
The 2 most commonly used are: Maven-archetype-quickstart and Maven-archetype-webapp two. We currently choose Maven-archetype-quickstart directly, click Next;
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/85/9C/wKiom1ep-8SzqhIEAACdHAcviJw651.png-wh_500x0-wm_3 -wmp_4-s_3304701732.png "title=" 006.png "alt=" Wkiom1ep-8szqhieaacdhacvijw651.png-wh_50 "/>
(3) Enter the group ID and Artifact ID; the previous one can be understood as a company domain name, the second is the project name, and finally click Finish. Such as:
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/9D/wKiom1ep_PPQkdG9AAB5ZDnczPs482.png-wh_500x0-wm_3 -wmp_4-s_3878524481.png "title=" 007.png "width=" "height=" 435 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px ; height:435px; "alt=" Wkiom1ep_ppqkdg9aab5zdnczps482.png-wh_50 "/>
This completes the construction of a simple MAVEN project.
(4) Look at the MAVEN catalog results and find a main, with a test. In general, we also want to store some configuration files, we can build a folder under Src/main called Resources.
Right-click this project (Hello-maven), choose Build Path--Configure build path ...--Select the Source tab--tap add Folder--> ; Add the Resources folder that we just added, such as:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/9D/wKiom1eqABriugs4AAD4QDHl_5E452.png-wh_500x0-wm_3 -wmp_4-s_1901987082.png "title=" 009.png "alt=" Wkiom1eqabriugs4aad4qdhl_5e452.png-wh_50 "/>
Once you have done this, you can see the resources folder in the Project view:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/85/9C/wKioL1eqAEexhTbZAAA5qrUhUGE767.png-wh_500x0-wm_3 -wmp_4-s_2971817468.png "title=" 010.png "width=" "height=" 192 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:200px ; height:192px; "alt=" Wkiol1eqaeexhtbzaaa5qruhuge767.png-wh_50 "/>
A brief introduction to 2.3 Pom.xml:
Pom.xml is the soul of the entire MAVEN project. The following 3 tags are defined, which are the coordinates of the project:
<groupId>com.vip</groupId> <artifactId>hello-maven</artifactId> <version>0.0.1- Snapshot</version>
<packaging>jar</packaging> <packaging> tags are packaged types, with jars, war, and so on.
Also, the Properties tab is important, which defines some variables and their property values for Pom.xml. For example, the following code snippet for Pom.xml:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> < junit.version>4.12</junit.version> </properties> <dependencies> <dependency> <grou Pid>junit</groupid> <artifactId>junit</artifactId> <version>${junit.version}</vers ion> <scope>test</scope> </dependency> </dependencies></project>
As the code above, we define a label "Junit.version" in the properties and the value is "4.12". Here we refer to this variable when we configure dependencies, the reference method is "${junit.version}". This way, in the system upgrade version number, and configure the parent project (parent project), it is very helpful to us, can not modify the dependencies dependency, and directly modify the value in the properties can be, very convenient!
2.4 Try to run the project:
Here's an attempt to run the new MAVEN project, right-click the project, run as, and see some of Maven's lifecycle plugins, clean, install, and more. Selecting "5 Maven Build" will allow us to enter the MVN command ourselves.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/85/9D/wKiom1eqBkCz3zi5AAGLn1oiJCE483.png-wh_500x0-wm_3 -wmp_4-s_245189026.png "title=" 011.png "alt=" Wkiom1eqbkcz3zi5aagln1oijce483.png-wh_50 "/>
I encountered an error while executing the MVN clean package,
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/85/9D/wKiom1eqCeaSCtv7AADzCVweI0k895.png-wh_500x0-wm_3 -wmp_4-s_1659371471.png "title=" 013.png "alt=" Wkiom1eqceasctv7aadzcvwei0k895.png-wh_50 "/>
Error message:
[ERROR] No compiler is provided in this environment. Perhaps is running on a JRE rather than a JDK?
[INFO] 1 Error
[INFO]-------------------------------------------------------------
[INFO]------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]------------------------------------------------------------------------
This error is mainly caused by an environment that does not specify a JDK, as follows:
Choose from Eclipse: Window > Preferences > Java > Installed JREs
, the default configuration for Eclipse is the path to the JRE, which needs to be changed to the path of the JDK.
This article is from the "Snowflake" blog, make sure to keep this source http://6216083.blog.51cto.com/6206083/1836346
Maven Quick Access Tutorial (i)