Maven

1.下载
2,解压E:\Program\Maven
3.新建系统变量M2_HOME 值为E:\Program\Maven
4.添加path:;%MAVEN_HOME%\bin
5.mvn -v测试
6.在d:新建dataware/maven
7.新建src文件夹和pom文件
<?xml version="1.0" encoding="utf-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>zttc.itat.maven</groupId>
  <artifactId>maven-ch01</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  </dependencies>
  </project>
 
 8.src文件下建main 和test文件夹
  main下建zttc.itat.maven.Helloworld类
package zttc.itat.maven;
public class Helloworld {

        /**
     * @param  args
     */
    public String sayHello(String name) {
        return "hello:"+name;

    }

}
mvn compile

[INFO] Compiling 1 source file to E:\Dataware\maven-ch01\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.287s
[INFO] Finished at: Sun Jan 24 16:40:42 CST 2016
[INFO] Final Memory: 10M/224M
[INFO] ------------------------------------------------------------------------
这时就会在项目下生成一个问价夹放class

修改pom
<?xml version="1.0" encoding="utf-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>zttc.itat.maven</groupId>
  <artifactId>maven-ch01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
 
  <dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
</dependency>

  </dependencies>
  </project>
  在test下面建立java\zttc\itat\maven\TestHelloMaven.java
 
package zttc.itat.maven;
import static org.junit.Assert.*;
import org.junit.Test;
public class TestHelloMaven{
    @Test
    public void  SayHello(){
        Helloworld hm=new Helloworld();
        String str=hm.sayHello("maven");
        assertEquals(str,"hello:maven");
    }
}
运行mvn test

[INFO] Compiling 1 source file to E:\Dataware\maven-ch01\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ maven-ch01 ---
[INFO] Surefire report directory: E:\Dataware\maven-ch01\target\surefire-report


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running zttc.itat.maven.TestHelloMaven
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.103 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.202s
[INFO] Finished at: Sun Jan 24 17:15:30 CST 2016
[INFO] Final Memory: 9M/177M
mvn clean
先mvn install
maven 可以引入其他项目的东西
  <dependency>
    <groupId>itaat.com</groupId>项目坐标
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>
自己指定工厂位置
conf ->setting ->local repository改变
并且拷贝一份到自己的项目下

你可能感兴趣的:(Maven)