Maven Getting Started Guide: Maven Quick start and easy to use

Source: Internet
Author: User

maven Getting Started Guide: Maven Quick start and easy to use Preface

Maven is an open source project management tool written in the Java language and is the top project of the Apache Software Foundation. Mainly used for project construction, dependency management, project information management.

MAVEN projects in the compilation, testing, packaging, will need from MAVEN's central warehouse (ie: the MAVEN organization published on the Internet, a site, which already contains the vast majority of the current mainstream jar package) download jar package, etc., if using a proxy server to surf the Internet, you need to configure a proxy server.

Understanding the "warehouse"

After the first run of Mvn-version, a. M2 directory is created under the user directory (for example: C:\Users\ Current user name \.m2\), which is Maven's "local Repository", which is a very important concept in Maven.

Imagine that we create many projects at the same time in our work, and each project may refer to some common jar packages (. NET is a DLL file), a practice is that each project, a copy of these dependent jar packages (or DLL files), it is obviously not good, the same files on the hard disk to save multiple copies, too much space, and these dependent jar package (or DLL file) version is not very good management ( For example, a common jar package, upgrading from 1.0 to 2.0, if all the items referencing this jar package need to be updated, each item must be modified.

The MAVEN repository solves these problems by creating a native repository on each machine, unifying the jar packages that all MAVEN projects rely on on the machine, and uniquely identifying them with the "coordinates" (note: coordinates are another important concept, and later, This is simply understood as a "unique identification of a jar package file name, version number", so that all MAVEN projects do not need to copy the jar package into the Lib directory as before, and the entire MAVEN project looks very refreshing.

How to import a maven project into MyEclipse

1. Open the MyEclipse tool, click File, select Import

2. Select the import type that is already present in the MAVEN project, and then next.

3. Click Browse to select the source of the MAVEN project to download, click Finish

4. Then you'll be stuck for a while, because the MAVEN project doesn't need to manually import the jar files, and the MAVEN project automatically downloads the required jars, so wait a little longer.

File/directory structure related conventions for MAVEN projects

Src/main/java-store project. java files;

Src/main/resources-Storing project resource files;

Src/test/java-Store the test class. java files;

Src/test/resources-Storage of test resource files;

Target-project output directory;

Pom.xml-maven core file (Project Object Model);

Create a MAVEN project using MyEclipse

MyEclipse provides a maven4myeclipse plugin that has built-in Maven installed, but we typically use MAVEN, which we downloaded in our own configuration, to add the maven we just downloaded in the installations option. Eclipse can install the M2eclipse plugin on its own.

1. Create a new Maven Project:

2. Select Workbench Location:

3. Select Maven archetype (Project skeleton), here we choose Maven-archetype-webapp:

4. Set Maven-related parameters, Group id,artifact id,version,package. Together, they form the coordinates of Maven:

Subsequent related configurations

1. After the project was created, we saw that MyEclipse created the src/main/resources for us by default and opened the project Properties-Java Build path-source column to see Src/main/java and Src/test/ja VA Display Missing:

Open the Libraries, edit the JRE environment, and select your own installed JDK:


At this time, Src/main/java and Src/test/java have come out, and then add their own src/test/resources directory:

2. Next, set up Project Facets. Select version of Java 1.7 and Dynamic Web Module 3.1:

3. Set the project output directory as follows:

4. Set the deployment packaging structure as follows to delete the test-related directories:

pom.xml file, adding related jar package dependencies

1. Open the Pom.xml file, we see that Maven has added a JUnit3.8.1 dependency for us, here we change to JUnit 4.11, and add the Servlet-api dependency package:

2. After saving, we added the relevant jar package automatically. At this point, the first missing SERVLET-API related to the error message is no longer:

Building and Deploying projects

1. Right-click Pom.xml-run as-maven-install:

2. Coming to the target folder, we see the deployment file that generated the project:

3. Deploy the project to the Tomcat application server to access the project:

Note

The content of this article is for the author to arrange Internet content. Please refer to the "References" section for details.

Reference Documents

Http://www.cnblogs.com/luotaoyeah/archive/2014/06/02/3764533.html

American and American pictures

Maven Getting Started Guide: Maven Quick start and easy to use

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.