What "maven" maven is and how MAVEN projects are built

Source: Internet
Author: User

Read Catalogue

    • Related books
    • What is maven?
    • How to use Maven in eclipse
    • What does the MAVEN project look like?
    • Commands used by Maven in eclipse

Objective:

  As a result of recent work study, always can meet Maven source code. Although the usual work does not use MAVEN, but in order to learn some source code, still need to understand the next. This article is not a comprehensive maven parsing, but a simple introduction, including how MAVEN is used in Eclipse, and how to take advantage of MAVEN engineering learning.

  Gradually, you will learn the following knowledge:

 MAVEN's related books!

What is maven?

How do I use Maven in eclipse?

What is Maven's project like?

Common commands for Maven in eclipse!

Back to top related books

First of all, two books are recommended, are online search for PDF. Because I do not have the job requirements, so it is just a simple understanding, and no in-depth research. Interested friends, can read more of these two books.

MAVEN's authoritative guide

"Maven Combat"

Back to the top what is maven?

Maven is a tool for building projects that easily manage the life cycle of your project. That is, the project's jar package relies on, develops, tests, releases packaging.

Let me summarize some of its features below, and look at these features, perhaps more about Maven.

1 Jar Package Dependency

This might be the most prominent feature of Maven. Using MAVEN does not require the Internet to download the jar package separately, only to configure the jar package dependencies in the configuration file Pom.xml, you can automatically download the jar package to our project. This way, when others develop or use this project, they do not need to copy the jar package back and forth, just copy the pom.xml to automatically download the jar packages.

Moreover, we download the jar package ourselves, and it is possible to create inconsistencies in the version so that it is possible that the code will run inconsistently during the collaborative development process. This problem does not occur by using Maven's exact matching jar package.

2 Project coordinates

MAVEN defines the project name with a specific identity, so that it can uniquely match other jar packages or be published so that others can use their own publishing products. This logo is called the coordinates, the long is actually very common, is simple XML only:

1<GroupId>com.test</GroupId>2<Artifactid>maventest</Artifactid>3<Version>0.0.1-snapshot</Version>4 <packaging>jar</ packaging>5 6 <name> Maventest</name >7 <url>http://maven.apache.org</url>                 

  groupId: The project name, since some items are not made of a jar package, but consist of a lot of jar packages. So this groupid is the name of the whole project.

  Artifactid: The name of the package.

  Version: revision number.

  Packaging: The type of package, usually a jar, or a war. If not, the default is the jar.

   name and the URL, one is the names and one is the address of Maven. The main is the above several parameters.

When you want to rely on what jar, you can rely on the following way:

1<Dependencies>2<Dependency>3<GroupId>junit</GroupId>4<Artifactid>junit</Artifactid>5 <version>3.8.1</ version>6 <scope>test </scope>7 </dependency> 8 </dependencies                 

The contents of each attribute are basically the same.

Note here that the naming rules for jar packages are:

  artifactid-version[-classifier]. Packaging

For example, the pom.xml generated jar package name above is:Maventest-0.0.1-snapshot.jar.

The classifier here is optional, but some projects may also need to export some attached files, such as Javadoc,source and so on, then this place will need to configure a string. It's usually jdkxxx or something like that.

3 Test Drive

MAVEN is a test-driven development idea, so the project was initially created with two folders, main and test. A Java file for placing the development, one for writing test unit tests. This allows you to design unit tests in advance of each development to help reduce bugs.

Back to top how to use Maven in eclipse

The eclipse I'm using has its own Maven plugin, so it can be created directly. This does not show you how to install MAVEN. Here's how MAVEN projects are created:

1 How to create a MAVEN project:

Click New directly, you can find the Maven tab, click Maven Project to create MAVEN project

2 Select the default project location

3 Create the project, red is the creation of the ordinary Maven project. Pink is the creation of Web engineering.

6 fill in the relevant GroupID Artifactid version and other information

Click Finish to create a simple MAVEN project.

Back to the top what does maven project look like?

The MAVEN project is generally structured as follows:

First_maven  |--pom.xml  '--src      |--main      |   | --java      |   |   '--com      |   |       '--Test      |   |           '--App.java      |   '--Resources      |       '--Meta-inf      |           '--application.properties      '--Test          '--Java              '--com                  '--Test                      '--Apptest.java   

pom.xml: A dependency used to define or add a jar package

  Src-main: For storing Java source files

  src-test: Used to store test cases.

The target folder may also appear under the project , which is used to generate the corresponding class file or the released Jar package.

Go back to the top of the eclipse in the MAVEN common commands

Click Run as to find a few MAVEN commands:

Maven Build:

This command is used to compile the MAVEN project, and the corresponding class file is generated in the classes in the target folder after executing the command.

Maven Clean:

Delete the target folder, which deletes the generated package packages and files such as class.

Maven Test:

Compile automatically before running all of the test cases.

Maven Install:

Publish builds the corresponding package packages.

Attention:

Note that the command above, build and test will generate the corresponding class file. That is, when you create a new MAVEN project, or clean a maven project, if you do not use these two commands, directly test against the class, will run out of Java.class.notfound error. Because the class file is not compiled at this time.

Unit tests can be performed on a class only after using the two commands above.

What "maven" maven is and how MAVEN projects are built

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.