Introduction to Maven

Source: Internet
Author: User
  1. What is Maven?
    Maven: Chinese translation, "expert ". There are basically two purposes:
    First, a build tool is used to build the source code into a publishable component. Similar to ant;
    The other is the project management tool.
    The official definition is as follows:
    Maven is a project management tool that contains a project object model, a set of standard sets, and a project life cycle ), A dependency management system and logic used to run the plug-in (GOAL) defined in the lifecycle phase (phase.

  2. Keywords in Maven
    Project
    : Maven can consider everything you want to build as a project. These projects are defined as engineering object models (POM, poject object model ). A project can depend on other projects. A project can also be composed of multiple sub-projects.
    POM: Pom (POM. XML) is the core file of Maven. It is a metadata file that instructs Maven how to work, similar to the build. xml file in ant. The pom file is located in the root directory of each project.
    Groupid: Groupid is the globally unique identifier of a project. Generally, it is the project name. Groupid facilitates the use of a complete package name to distinguish a project from other projects with similar names.
    Dependency: To be able to build or run, a typical Java project depends on other packages. In Maven, these dependent packages are called dependency. Dependency is generally the artifact of other projects.
    Plug-in: Maven is organized by plug-ins. Every function of Maven is provided by plug-ins. The plug-in provides goal (similar to the target in ant) and completes the work based on the metadata found in pom. The main Maven plug-in is written in Java, but it also supports plug-ins written in beanshell or ant script.
    Repository: The repository is used to store artifact. It can be a local repository or a remote repository. Maven has a default remote repository-Central, which can download artifactfrom http://www.ibiblio.org/maven2. On Windows, the default address of the local repository isUser_home\. M2 \ repository.
    Snapshot: You can (or should) have a special version in the project. Its version number includesSnapshot. This version tells Maven that the project is in the development stage and will be updated frequently (but not yet released ). When other projects use artifact of this type, Maven searches for the latest version of artifact in the repository, and automatically downloads and uses the latest version.

  3. Download and install Maven (Windows)
    Http://maven.apache.org/download.html
    Download the latest version of Maven 3.0.4 (Binary zip)
    Decompress to D: disk. (because Maven is based on Java, you must first install JDK and set the java_home variable .)
    Add the following environment variables-
    Maven_home: D: \ apache-maven-3.0.2
    Maven: % maven_home % \ bin
    (Optional) maven_opts:-xms256m-xmx512m

    Add % Maven % before path;
    The installation is complete.
    You can enter MVN-version in the command line. To verify whether the installation is successful.

  4. Maven getting started instance
    1) create a project my-app.
    First, use CD to switch to the path where the project is to be placed, and then type
    mvn archetype:create -DgroupId=com.tootuu.app -DartifactId=my-app

    If this command is run for the first time, it will take a long time to run, because it will download some of the latest Toolkit (artifacts) to your local repository (User_home\. M2 \ repository)
    After the command is executed, a directory of my-app is generated. (This directory contains a pom. xml file and a SRC folder. The src/main/Java directory contains the source code of the project. The src/test/Java directory contains the test code of the project to automatically generate com. tootuu. app. app. java Hello world test file)
    2) Compile and Package

    mvn package

    After the execution is complete, the target directory is generated under the my-app Directory, which contains the generated my-app-1.0-SNAPSHOT.jar package file.
    3) Then you can run the JAR file using the Java command.

    java -cp target/my-app-1.0-SNAPSHOT.jar com.tootuu.app.App

    Print "Hello world! "

  5. Common commands. (Mvn xxx)
    MVN archetype: Create: Create a Maven Project
    Validate:Verify that the project is correct and that all required resources are available.
    Compile:Compile the source code of the project.
    Test:Use a suitable unit test framework to test compiled source code. These tests do not need to be packaged and deployed.
    Package:Package compiled code into a publishable format, such as jar.
    Integration-test:If necessary, process and release the package to an environment that can be integrated for testing.
    Verify:Run all the checks to verify whether the package is valid and meets the quality standards.
    Install:Installing the package in the local repository can be used by other projects as dependencies.
    Deploy:Run the command in the integration or release environment to copy the final version package to a remote repository, so that other developers or projects can share the package.
    Clean:Clear previously constructed artifacts (in Maven, the packages generated by the project are called artifact ).
    Site:Generate a document site for the project.

  6. Reference resources
    [1] Maven official website. http://maven.apache.org
    [2] Maven pom file reference structure. http://maven.apache.org/ref/current/maven-model/maven.html
    [3] Super Pom. http://maven.apache.org/guides/introduction/introduction-to-the-pom.html
    [4] list of Maven main plug-ins. http://maven.apache.org/plugins
    [5] Maven basic user guide. http://maven.apache.org/guides/index.html
    [6] better build with Maven. http://www.mergere.com/m2book_download.jsp-strongly recommended
    [7] Introduction to maven2. http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven_p.html
    [8] reveal maven2 Pom. http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-maven.html
    [9] Maven makes things simple. http://www-128.ibm.com/developerworks/cn/java/j-maven
    [10] Maven documentation collection. http://docs.codehaus.org/display/MAVENUSER/Home
    [11] Effective Use of maven2 site generation function. http://www.matrix.org.cn/resource/article/44/44491_Maven2.html
    Download example program: http://www.blogjava.net/files/jiangshachina/maven.rar

 

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.