Maven getting started

Source: Internet
Author: User

It has been said that Maven is a project cycle management software for a long time, because the previous projects are not allowed to access the Internet, so Maven cannot be used to download jar packages. Now, after job hopping, you can directly use a leased line to connect to the Internet and finally have the chance to use Maven. Therefore, you can simply write the maven entry-level documents.

First, download Maven (because I use eclipse for coding in windows, so I download the Windows version of Maven ). Install the SDK directly after downloading it, and configure three environment variables:

1. maven_home = installation path (e. g C: \ apache-maven-3.0)

2. MAVEN = % maven_home % \ bin

3. Add % maven_home % To the PATH variable.

OK. Enter MVN-V in cmd. If you see

++ ++

C: \ Users \ Eric> MVN-version
Apache Maven 3.0.3 (r00005438; 01:31:09 + 0800)
Maven home: D: \ Program Files (x86) \ apache-maven-3.0.3
Java version: 1.7.0, vendor: Oracle Corporation
Java home: C: \ Program Files \ Java \ jdk1.7.0 \ JRE
Default locale: zh_cn, platform encoding: GBK
OS name: "Windows 7", version: "6.1", arch: "amd64", family: "Windows"

++ ++

The installation is successful.

Deploy the first Maven project. Create a Maven project in eclipse.

This is the configured Pom. XML content.

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3   <modelVersion>4.0.0</modelVersion> 4  5   <groupId>org.andy.maven</groupId> 6   <artifactId>MavenTest</artifactId> 7   <version>0.0.1-SNAPSHOT</version> 8   <packaging>jar</packaging> 9 10   <name>MavenTest</name>11   <url>http://maven.apache.org</url>12 13   <properties>14     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>15   </properties>16 17   <dependencies>18     <dependency>19       <groupId>junit</groupId>20       <artifactId>junit</artifactId>21       <version>3.8.1</version>22       <scope>test</scope>23     </dependency>24   </dependencies>25 </project>

We compile a Java class

 1 package org.andy.maven.MavenTest; 2  3 public class MyMavenTest { 4  5     public String getString(String s){ 6         System.out.println("In the getString the para is "+s); 7         return "SUCCESS"; 8     } 9     10     public static void main(String[] args) {11         // TODO Auto-generated method stub12         System.out.println("In the main is OK");13     }14 15 }

Right-click Pom. xml and choose run as> Maven build. Input "clean compile" in goals, indicating that the file is cleared first and then compiled again ).

 1 [INFO] Scanning for projects... 2 [INFO]                                                                          3 [INFO] ------------------------------------------------------------------------ 4 [INFO] Building MavenTest 0.0.1-SNAPSHOT 5 [INFO] ------------------------------------------------------------------------ 6 [INFO]  7 [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ MavenTest --- 8 [INFO] Deleting D:\scala-workspace\MavenTest\target 9 [INFO] 10 [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ MavenTest ---11 [debug] execute contextualize12 [INFO] Using ‘UTF-8‘ encoding to copy filtered resources.13 [INFO] skip non existing resourceDirectory D:\scala-workspace\MavenTest\src\main\resources14 [INFO] 15 [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ MavenTest ---16 [INFO] Compiling 1 source file to D:\scala-workspace\MavenTest\target\classes17 [INFO] ------------------------------------------------------------------------18 [INFO] BUILD SUCCESS19 [INFO] ------------------------------------------------------------------------20 [INFO] Total time: 2.027s21 [INFO] Finished at: Mon Jul 21 21:52:08 CST 201422 [INFO] Final Memory: 9M/23M23 [INFO] ------------------------------------------------------------------------

The 18 lines indicate that Maven has been compiled successfully.

Maven commands in Eclipse:

Maven clean -- clear the current project

Maven build -- execute Maven commands

Maven install -- generate a jar package

Update Project -- If you modify the dependency information in POM (e. g version, add/delete jar packages, etc.), update the current project

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.