Apache-maven Learning

Source: Internet
Author: User
Tags maven central

Before listening to the students said about their company using the MAVEN framework to do project management, but also with him to participate in a small project, but did not carefully to do, and now study hard.

Article reprinted from: Yi Hundred tutorials [http:/www.yiibai.com]

Apache maven is a software project management and Integration tool. Based on the concept of the Project object Model (POM), MAVEN can manage project builds, reports, and files from a central piece of information.

This tutorial will show you how to use Maven in Java development, or any other programming language for any project.

What is maven?

MAVEN is a project management and integration tool. MAVEN provides developers with a complete life cycle framework. The development team can automate the construction of the project's underlying tools, MAVEN uses the standard directory structure and the default build life cycle.

In multiple development team environments, MAVEN can set up the configuration work in a very short time by standard. Because most projects are easy to set up and reusable, MAVEN makes it easier for developers to create reports, check, build, and test automation settings.

MAVEN provides a way for developers to manage:

    • Builds

    • Documentation

    • Reporting

    • Dependencies

    • SCMs

    • Releases

    • Distribution

    • Mailing list

In summary, Maven simplifies and standardizes the project construction process. Handles the seamless connection of compilation, distribution, documentation, team collaboration, and other tasks. Maven increases reusability and is responsible for building related tasks.

MAVEN History

MAVEN was originally designed to simplify the construction of the Jakarta Turbine project. In several projects, each project contains different ant build files. The jar checks to CVS.

The Apache organization development MAVEN can build multiple projects, publish project information, project deployment, and provide team collaboration and help with JAR files in several projects.

Maven Target

The main goal of MAVEN is to provide developers with:

    • The project is a comprehensive model that is reusable, easy to maintain and easier to understand.

    • Plug-ins or interactive tools, this declarative pattern.

The structure and content of the MAVEN project are declared in an XML file, pom.xml the Project object Model (POM), which is the basic unit of the entire MAVEN system. For more information, see the section of Maven Pom.

Apache Maven is an innovative software project management tool that provides a new concept for project object Model (POM) files to manage project builds, dependencies, and documentation. The most powerful feature is the ability to automatically download project-dependent libraries.

In this tutorial, it provides many examples and explanations of how to use Apache Maven 3.x.

MAVEN Installation and Configuration

The Installation guide for Windows.

One, install MAVEN on Windows

To install Apache maven on a Windows system, simply download the Maven zip file and unzip it to the directory you want to install and configure the Windows environment variable.

The tools you need:

    1. JDK 1.8
    2. Maven 3.3.3
    3. Windows 7 Note
MAVEN 3.2 requires JDK 1.6 or later, and Maven 3.0/3.1 requires JDK 1.5 or more 1. JDK and Java_home

Make sure that the JDK is installed and that the "java_home" variable is joined as a Windows environment variable.

2. Download Apache Maven

Visit the MAVEN official website, open and find the download link as follows:

Download the Maven zip file, for example: Apache-maven-3.3.3-bin.zip, and unzip it to the folder where you want to install MAVEN.

Let's say you unzipped to this folder –d:\software\yiibai.com\apache-maven

Note: In this step, just folders and files, installation is not required for 3. Add M2_home and Maven_home

Add the M2_home and Maven_home environment variables in windows and point them to your MAVEN folder.

M2_home or Maven_home
Maven says it just adds M2_home, but some projects still refer to Maven's folder Maven_home, so add it for security. 4. Add to environment variable-PATH

Update the PATH variable and add the Maven Bin folder to the last –%m2_home%\bin of path, so you can run the MAVEN command everywhere.

5. Verification

Complete to verify it, execute mvn–version at the command prompt, such as output results:

C:\users\administrator>mvn-versionapache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19 : 57:37+08:00) Maven Home:d:\software\yiibai.com\apache-mavenjava version:1.8.0_40, vendor:oracle CorporationJava Home:d:\program Files\java\jdk1.8.0_40default LOCALE:ZH_CN, platform Encoding:gbkos name: "Windows 7", Version: "6.1", Arch: "AMD64", Family: "DOS"
Ii. enabling MAVEN-enabled proxy access

If your company is building a firewall and using an HTTP proxy server to prevent users from connecting directly to the Internet. If you use a proxy, MAVEN will not be able to download any dependencies.

In order to make it work, you must declare the proxy server in the Maven configuration file: Settings.xml.

1. MAVEN configuration file

Locate the file {m2_home}/conf/settings.xml, and write your proxy server information configuration. Note: {M2_home} = D:\software\yiibai.com\apache-maven

{M2_home}/conf/settings.xml

<!--proxies

   | This is a list of proxies which can being used on this machine to connect to the network.   Unless otherwise specified (by system property or command-line switch), the first proxy   | specification in this list m Arked as active would be used.   | -  <proxies>    <!--proxy     | Specification for one proxy, to is used in connecting to the network.     |    <proxy>      <id>optional</id>      <active>true</active>      <protocol> http</protocol>      <username>proxyuser</</username>      <password>proxypass</ password>      

Uncomment the proxy option and fill in the details of your proxy server.

<!--proxies   | This is a list of proxies which can being used on this machine to connect to the network.   Unless otherwise specified (by system property or command-line switch), the first proxy   | specification in this list m Arked as active would be used.   | -  <proxies>      <proxy>      <id>optional</id>      <active>true</ active>      <protocol>http</protocol>      <username>yiibai</username>      < password>password</password>      
2. Save the file

When finished, Apache Maven should be able to connect to the Internet immediately via a proxy server.

Note: Restarting is not required. Maven is just a command, and when you call it, it will read the file again. MAVEN resource Pool

Maven location, Central and remote repository configuration and interpretation, some terms may need to be understood before Maven is used.

    • Maven Local Repository
      Maven's local repository is a dependent library for storing projects, and the default folder is the ". M2" directory, which may need to be changed to another folder.
    • Maven Central repository
      The MAVEN central repository is the default location for the dependent libraries that Maven uses to download all projects.
    • How do I download from the MAVEN remote repository? , how do I add a remote library?
      Not all inventory is stored in MAVEN's central repository, and many times you need to add some remote repositories to download libraries from other locations instead of the default central repository.
    • Maven dependency mechanism
      The article here is about the differences between traditional and maven-dependent libraries, and explains where Maven will search for these libraries.
    • Customizing libraries to the MAVEN local repository
      Many libraries still do not support MAVEN's pom.xml concept, and there is a guide to how to include "Non-MAVEN support" libraries into the MAVEN local repository.
Based on Maven project and Eclipse IDE

The example is to use MAVEN to create a Java project and a Web application, and to demonstrate how to import it into the Eclipse IDE.

    • Creating a Java project using MAVEN
      Use Maven to create a Java project.
    • Convert a MAVEN-based Java project to support the Eclipse IDE
      Directs the conversion of MAVEN-based Java projects to support the Eclipse IDE.
    • Create a Web application project using Maven
      Use MAVEN to create a Web application project.
    • Convert a MAVEN-based Web application to support the Eclipse IDE
      Maven transforms web-based applications to support the guidelines in the Eclipse IDE.
    • Create a project using the Maven template
      Alternatively, you can create a standard project from a Maven template.
MAVEN Basic Operations

Some basic operations, compilation, build, unit testing, installation, site generation and MAVEN-based deployment projects.

    • Building projects with Maven
      "MVN package" to build the project
    • Using MAVEN cleanup Project
      "Mvn clean" to clear the project
    • Run unit tests using MAVEN
      "MVN test" to perform unit tests
    • Installing the project to the MAVEN local repository
      "MVN Install" package and deploy projects to the local repository
    • Build a MAVEN-based project document site
      "MVN site" to generate an informational document site for your project
    • Deploying a site using "MVN site-deploy" (WebDAV example)
      "MVN site-deploy" deployment of automatically generated document site-to-server via WebDAV
    • Deploying a Maven-based war file to Tomcat
      "MVN Tomcat:deploy" deployed to Tomcat with WAR files
Maven Reference
    • Apache Maven Official Tutorial
    • Apache Maven (Wiki)

Apache-maven Study (Turn)

Related Article

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.