MAVEN entry (1), MAVEN entry (

Source: Internet
Author: User

MAVEN entry (1), MAVEN entry (
I. Basic concepts of Maven

  Maven is a cross-platform project management tool. Mainly serves Java platform-based project construction, dependency management and project information management.

1.1. Project Construction

The project construction process includes the following steps: clean up a project, compile a project, test a project, generate a test report, package a project, and deploy a project, these six steps are the complete construction process of a project.

IDEAL project construction is highly automated, cross-platform, reusable components, and standardized. maven can help us complete the above-mentioned project construction process.

1.2 Dependency Management

Dependencies refer to the dependencies between jar packages, such as when we build a Struts2 development framework, light has struts2-core-2.3.16.3.jar jar package is not good, struts2-core-2.3.16.3.jar also depends on other jar package, dependency management refers to using Maven to manage the jar packages used in the project. The Maven management method is to "automatically download the jar packages required by the project, unified management of dependencies between jar packages ".

1.3 Basic maven content

Maven Conventions: Specify the directory under which the java source code must be stored and the compiled java code must be stored.

Maven action: maven has corresponding shell commands for every process of building a project.

Maven configuration file: you only need to define a pom. xml file in the project, and then place the source code to the default directory. Maven will help us deal with other things.

Maven management: dependency management and repository management.

  

 

2. Maven download and configuration environment variable 1. Download

: Http://maven.apache.org/download.cgi

Download the zip package. maven is a lightweight green tool that can be used to decompress and configure environment variables. (The premise is that the java environment has been installed on the machine)

2. Configure Environment Variables

Vi open the. zshrc file in the personal directory (use bash to open the. bash_profile file ).

Edit the. zshrc file as follows:

    

The main content is the content in the red box. Other content is the environment variable of my own machine, which is irrelevant to maven.

 

MAVEN_HOME is the zip decompression address of maven, and then configure the maven bin directory to the path. In this way, you can directly perform maven operations using shell commands.

    

Enter source. zshrc in the terminal window (bash users should enter source. bash_profile ).

 

Input mvn-v directly. The following information indicates that the configuration is successful.

    

Iii. Simple Application of maven 1. Directory conventions:

| ---- Src
| ---- Main
| ---- Java -- stores the. java file of the project.
| ---- Resources -- Stores project resource files, such as spring and mybatis configuration files.
| ---- Test
| ---- Java -- stores all test. java files, such as the JUnit test class.
| ---- Resources -- Stores project resource files, such as spring and mybatis configuration files.
| ---- Target -- project output location
| ---- Pom. xml ---- identifies a Maven Project

2. manually create a maven java Project

Follow the maven directory conventions to create folders and Their java files:

    

Create the pom. xml file in the root directory of the project and make the following Configuration:

    

<? Xml version = "1.0" encoding = "UTF-8"?> <Project xmlns = "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"> <! -- All Maven projects must configure these four configuration items --> <modelVersion> 4.0.0 </modelVersion> <! -- GroupId refers to the project team with the project name. The default package name is --> <groupId> com. xxlxx. maven. hello </groupId> <! -- ArtifactId refers to a module in the project. The default naming method is "project name-Module name" --> <artifactId> hello-maven </artifactId> <! -- Version indicates the version. Here, the SNAPSHOT version of Maven is used --> <version> SNAPSHOT-0.0.1 </version> </project>

 

Use Maven to compile HelloMaven. java, first go to the project root directory, and then use the command"Mvn compILe"To compile:

File directory before Compilation:

    

Compilation information:

    

Compiled file directory:

    

You can see that there is another target directory. The target directory contains the classes folder, and the folder contains the class file compiled by the java file in the src directory.

Ps. Another command is"Mvn clean", This command is to delete the target file under the project root directory.

Iv. settings. xml and repository of Maven 1. Local dependency repository

By default, the repository is located in the. m2 folder under the user root directory. When executing the "mvn compile" and "mvn clean" commands for the first time, Maven downloads the required jar package to the local repository in the central repository, that is, the repository folder. When the two commands are executed for the second time, the required jar packages are stored in the local repository, so they can be used directly, this saves you the time to download the jar package from the central repository.

2. maven Configuration File settings. xml

The xml file has two copies. The first copy is in the conf folder under MAVEN_HOME and is the maven global configuration file. The second part is the maven user configuration file in the. m folder described above. Both configuration files are called settings. xml.

    

Use this xml file to customize the location of the repository:

    

        

 

    

    

 

 

    

 

 

 

    

    

    

 

  

  

 

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.