Project management Tools: A summary of MAVEN usage methods

Source: Internet
Author: User

First, the concept

MAVEN is a project management and building automation tool. MAVEN provides developers with the ability to build a complete life cycle framework, and the development team can automate the building of the project's underlying tools. The results of a MAVEN project are as follows:

  

Second, MAVEN installation

Before installing MAVEN, make sure to install the JDK and then download the latest version of the binary ZIP archive package on Apache's official web http://maven.apache.org/download.cgi.

Download the decompression and put it on a local path, then configure the MAVEN environment variable:

New variable name M2_home:c:\program files\apache-maven-3.3.9

Variable Value: C:\Program files\apache-maven-3.3.9

After the configuration is complete, enter mvn-version at the Windows command prompt, indicating that the installation was successful if displayed:

  

In Eclipse 4.0 or later, the Maven plugin is inherited and can be configured in Windows-Preference-A:

  

  

Iii. Common Commands
mvn archetype:create Creating a maven project MVN compile compiling source code mvn deploy release Project MVN test-install- Dmaven.test.skip=true: RePack the previous package and skip the test class
Iv. life cycle

The life cycle of MAVEN is designed to abstract and facilitate unification of all building processes.

1. Clean Cleanup Project

Pre-clean perform pre-cleanup work

Clean cleans up all files generated by the previous build

Post-clean performing clean-up files

2. Default Build Project

Compile compiling the source code in the project

Test is tested using the appropriate unit test framework, which is not packaged or deployed

Test-compile compiles the source code that needs to be tested to the path, typically compiling the Java file in the Src/test/java directory into the test classpath directory of the target output

The package accepts compiled code and is packaged into a published format, such as a jar

Install installs the package to the local repository and provides dependencies to other local references

3. Site Build Project Sites

Pre-site What to do before you build the project site

Site-generated Project Web document

Post-site the work to be done after building the project site

Site-deploy publishing the generated site to the server

V. First MAVEN Project

Create a new MAVEN project in Eclipse:

  

  

The result of the finish project is:

  

When you build a Web project in Eclipse, it's much the same as above, and it's important to choose Maven-archetype-webapp when choosing archetype.

The Pom file is:

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.xj.webdemo</groupId>  <Artifactid>Webdemo</Artifactid>  <Packaging>War</Packaging>  <version>0.0.1-snapshot</version>  <name>Webdemo Maven Webapp</name>  <URL>http://maven.apache.org</URL>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>4.10</version>      <Scope>Test</Scope>    </Dependency>    <Dependency>        <groupId>Javax.servlet</groupId>        <Artifactid>Javax.servlet-api</Artifactid>        <version>3.0.1</version>        <Scope>Provided</Scope>    </Dependency>  </Dependencies>  <Build>    <Finalname>Webdemo</Finalname>    <Plugins>        <plugin>            <groupId>Org.apache.tomcat.maven</groupId>            <Artifactid>Tomcat7-maven-plugin</Artifactid>            <version>2.2</version>            <executions>                <Execution>                    <Phase> Package</Phase>                    <Goals>                        <goal>Run</goal>                    </Goals>                </Execution>            </executions>        </plugin>    </Plugins>  </Build></Project>
View Code

Then run, you can enter localhost:8080 in the browser, you can access the.

Vi.. pom file

All configurations for a project are placed in the Pom file: Define the type of project, name, manage dependencies, customize plug-in behavior, and so on.

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.xj.maven</groupId>  <Artifactid>Hello</Artifactid>  <version>0.0.1-snapshot</version>  <Packaging>Jar</Packaging>  <name>Hello</name>  <URL>http://maven.apache.org</URL>  <Properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  </Properties>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>4.10</version>      <Scope>Test</Scope>    </Dependency>  </Dependencies></Project>

In the Pom file

 < groupId ></ groupId >  < Artifactid ></ Artifactid >  < version ></ version >

Called coordinates, it can uniquely determine a project, with MAVEN coordinates, which we can use to specify other projects, plugins, or parent projects on which our project depends.

Vii. Maven Library

When you run the MAVEN command for the first time, you need an Internet connection because it wants to download some files from the Web, and the MAVEN default remote library is http://repo1.maven.org/maven2. This remote repository has MAVEN's core plug-in and the jar files available for download.

However, not all jar files can be downloaded from remote libraries, such as our own projects, which can be customized in-house or manually downloaded and installed with the required jar files to the local library.

A local library is a copy of maven that is stored on the local machine after the plugin or JAR file has been downloaded. On Linux, it's located on ~/.m2/repository, on Windows XP, on C:\Documents and Settings\username\.m2\repository, on Windows 7, in C:\Us Ers\username\.m2\repository. When Maven looks for the jar file that it needs, it looks for it in the local library and only finds it in the remote library if it can't find it.

Run the following command to install our HelloWorld project to a local library:

$MVN Install

Viii. references

1, http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html

2, http://mvnrepository.com/

Project management Tools: A summary of MAVEN usage methods

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.