Maven installation and configuration

Source: Internet
Author: User

1. What is Maven?

Maven is a cross-platform project management tool that mainly serves project construction, dependency management, and project information management based on the Java platform.

1. Highly Automated Project Construction

2. automatically download the jar package for unified dependency management

3. Manage the project name and developer information


Ii. Why Maven?

1. disadvantages of using ide:

A. There are many manual operations, and compilation, testing, deployment, and other work are independent, which is difficult to complete in one step.

B.) The IDE configuration varies with each other, and errors may occur when local code is compiled in another place.


2. disadvantages of ant:

A.) There is no agreed directory structure

B) You must specify what ant will do, when it will do it, and then compile and package it.

C.) If there is no life cycle, you must define the job sequence and its implementation.

D.) No integration dependency management


3. advantages of using Maven:

A.) have the agreed directory structure, know where your code is, and where to put it
B. Have a life cycle. For example, execute MVN install to automatically execute build processes such as compilation, testing, and packaging.
C.) define a pom. xml file and put the source code in the default directory. MAVEN will help you deal with other tasks.
D. Have dependency management and warehouse management



3. Install Maven

1. Check JDK installation (version 1.6 is required)
Echo % java_home %
Java-version
2. Decompress apache-maven-3.0.3-bin.zip. For example, extract the package to the following directory (it is best not to include text in the decompressed directory)



3. Set the system environment variable, maven_home



4. Set the environment variable path and add % maven_home % \ bin to the path. Be sure to use a semicolon to separate it from other values.



5. verify whether the installation is successful. Open the CMD window and click MVN-V to view the installation result.



4. First Maven Project

1. Create a directory structure agreed by Maven at the same time as the hello Project
Hello
| ------ SRC
| ------ Main
| ------ Java
| ------ Resources
| ------ Test
| ------ Java
| ------ Resources
| ------ Pom. xml

2. Create Pom. XML in the project Hello root directory

<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">  <modelVersion>4.0.0</modelVersion>  <groupId>com.zdp.maven</groupId>  <artifactId>Hello</artifactId>  <version>0.0.1-SNAPSHOT</version>  <name>Hello</name><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.9</version><scope>test</scope></dependency></dependencies></project>

3. Create a file hello. Java in the src/main/Java/COM/zdp/Maven directory.
package com.zdp.maven;public class Hello {public String sayHello(String name){return "Hello "+name+"!";}}

4. Create the test file hellotest. Java in the/src/test/Java/COM/zdp/Maven directory.
package com.zdp.maven;import org.junit.Test;import static junit.framework.Assert.*;public class HelloTest {@Testpublic void testHello(){Hello hello = new Hello();String results = hello.sayHello("litingwei");assertEquals("Hello litingwei!",results);}}

5. Test it:

A.) Open the CMD command line and enter the root directory of the hello project to execute the MVN compile command to view the root directory changes.
B.) enter the MVN clean command in cmd and check the root directory again.
C.) enter the MVN clean compile command in cmd to view the root directory changes.
D.) enter the MVN clean test command in cmd to view the root directory changes.
E.) input the MVN clean package command in cmd to view the root directory changes.




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.