Maven (maven Summary 2 of the project management tool series), maven Project Management

Source: Internet
Author: User

Maven (maven Summary 2 of the project management tool series), maven Project Management

What is maven?

Download and install maven

Learn about mavenWarehouse

Configure maven in eclipse

Create a maven Project

Convert a maven project to a web project

 1. What is maven?

Maven is a project management and integrated tool. Maven simplifies and standardizes the project construction process. Seamless integration of compilation, assignment, documentation, team collaboration, and other tasks. Maven is a more advanced project management tool than Ant. It uses a "convention over configuration (CoC)" policy to manage projects.

What's wrong if you don't use maven?

1. in development, to ensure that the compilation is passed, we will search for jar packages everywhere. When the compilation is passed and running, we find that "ClassNotFoundException", what we think of is, is the jar package still poor?

2. the directory structure of each Java project does not have a uniform standard, and the configuration files are everywhere. The unit test code should be put there without an authoritative specification.

Therefore, Maven mainly implements the following two tasks:

1. Uniform development specifications and tools

2. unified management of jar packages

In short, Maven simplifies and standardizes the project construction process.

2. Download and install maven

2.1 Download the Maven compressed package

Maven: http://maven.apache.org/download.cgi

Download the *. Zip package in the window system and download the. GZ package in linux.

 

Unzip to the local, because I write this tutorial When the computer installed, And I downloaded the maven-3.0.5, decompress TO THE FOLLOWING path (extract directory do not have text, do not have space ):

 

2.2 set the system environment variable, MAVEN_HOME

This variable points to the Maven installation path. Here my path is E: \ javaEdit \ maven \ apache-maven-3.0.5

2.3 set the environment variable Path

Add % MAVEN_HOME % \ bin to Path. Be sure to use semicolons (;) to separate them from other values.

The key command of the Maven tool is the mvn. bat command in the Path % MAVEN_HOME % \ bin. Therefore, to enable the operating system to recognize this command, you must set the environment variable Path.

2.4 verify that the installation is successful

Open cmd and enter:

Mvn-v

 

Maven is successfully installed!

3.Learn about maven Repository

 Before using Maven, we must know how Maven manages jar packages. This is what the Maven repository is doing.

The most direct benefit of using Maven is the unified management of jar packages. Where are these jar packages stored? They are in your local repository. The default address is C: \ Users \ User Name. in the m2 directory (of course, you can modify the default address). Next we will modify the default address.

In fact, we can understand the local repository as "cache" to store jar packages. When developing a project, the project first obtains the jar package from the local repository. When the specified jar package cannot be obtained, the local repository downloads the jar package from the remote repository (or central repository, and "cache" to the local repository for future use.

The remote repository (central repository) is officially provided by Maven and can be accessed through http://search.maven.org. In this way, the local repository will grow with the project accumulation. The following figure shows the relationships between projects, local warehouses, and remote warehouses.

Modify the default configuration and replace the specified directory with the default C: \ Users \ Username. m2 directory as our local repository:

Modify the maven \ apache-maven-3.0.5 \ conf \ setting. xml file:

Console input:

Mvn help: system

Effect:

After executing this command, there will be a lot of files under E: \ javaEdit \ maven \ Repositories \ Maven. These files are the files that maven downloads from the central repository to the local repository, maven has started to work for us.

4. Configure maven in eclipse

4.1configure maven plug-in eclipse

Eclipse plug-ins are installed in two ways: online and offline. We recommend that you use the offline method for the two installation methods, which is more convenient and simple.

4.1.1 online Installation: Using Help --> Install New Software, you can enter an HTTP address for installation, which is simple and easy to operate. However, it also has advantages and disadvantages, that is, the download speed is slow, or sometimes you cannot find the plug-in to be installed. Use the first method for installation. Enter the http address: http://m2eclipse.sonatype.org/sites/m2e to check the installation. Wait until it is downloaded and installed. Then restart eclipse.

 

4.1.2 offline Installation:

1. Get the three folders zest, m2e and m2e-extras, copy them to the myplugins directory of the eclipse installation directory (create a new one without this directory)

 

). The content of each file is as follows:

Path = E: \ javaEdit \ maven \ apache-maven-3.0.5 (you need to change the red path to the path of your local actual plug-in)

Restart eclipse and click windows à preferences to view maven.

Benefits of link: This method has low coupling. To uninstall it, you only need to modify the file in the dropins directory.

4.2 configure maven

Click Installations-> add to select the maven installation directory.

 

5. Create a maven Project

 On the Eclipse menu bar, choose File> New> Other> Maven.

Select Maven Project, select Create a simple project (skip archetype selection), and then click Next

Enter the Group id and Artifact id. The default Version and Packaging are jar, Name, and Description.

 

Group Id: the developer's domain name of the project.

ArtifactId: Specifies the project name.

Packaging: specifies the type of project packaging.

Version: version of the specified project.

Then click Finish ,:

  • src/main/java: This directory mainly contains the java source code;
  • src/test/java: This directory is mainly used to store test code;
  • Maven Dependencies: The jar files managed by Maven are mainly used here;
  • target: Used to store the bytecode files compiled by Maven;
  • pom.xml: All calledProject Object ModelThe project object model defines the basic information of a project, describes how a project is built, and declares project dependencies.
  • src: Used to store other files and other resources used in main and test.

 

Create a simple maven project. If you want to create a Maven web project, change the Packaging type above to war, and click Finish ,:

 

If the error "web. xml is missing and <failOnMissingWebXml> is set to true" is displayed, the solution is as follows:

6.Convert a maven project to a web project

6.1Right-click the project and choose properties.

Select the red box in:

6.2Set deployment assembly

Right-click the project and choose properties> Deployment Assembly.

Right-click the project to open this window. A Deployment Assembly will appear in the list on the left. Click it. (because test is used for testing and does not need to be deployed, you can delete it)


Set to publish the jar package of Maven to lib.

Project management tool series:

Ant (project management tool series ant Summary 1)

Maven (project management tool series maven Summary 2)

Svn (project management tool series svn Summary 3)

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.