标签:
maven 版本与 jdk 对应的关系: http://maven.apache.org/docs/history.html ,这里使用的是 3.2.5,对应jdk 1.6.
下下来之后便是配置环境变量 .一个 M2_HOME 一个 path 。
cmd 窗口下用 mvn -v 来查看是否安装成功。
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>com.qcm</groupId> 6 <artifactId>mvn-ch1</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 10 <properties> 11 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 12 </properties> 13 14 <dependencies> 15 <dependency> 16 <groupId>junit</groupId> 17 <artifactId>junit</artifactId> 18 <version>4.10</version> 19 <scope>test</scope> 20 </dependency> 21 </dependencies> 22 </project>
1 package com.qcm; 2 3 public class HelloMaven{ 4 5 public String sayHello(String string){ 6 7 return "hello:"+ string ; 8 } 9 10 }
创建测试类
1 package com.qcm; 2 3 import org.junit.*; 4 import static org.junit.Assert.*; 5 6 public class HelloMavenTest{ 7 8 @Test 9 public void testSayHello(){ 10 HelloMaven hm = new HelloMaven(); 11 String str = hm.sayHello("maven"); 12 assertEquals(str,"hello:maven"); 13 14 } 15 16 }
接下来就可以在 cmd 窗口下 进入 mvn-ch1 目录下:
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>com.qcm</groupId> 6 <artifactId>mvn-ch2</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 10 <properties> 11 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 12 </properties> 13 14 <dependencies> 15 <dependency> 16 <groupId>junit</groupId> 17 <artifactId>junit</artifactId> 18 <version>4.10</version> 19 <scope>test</scope> 20 </dependency> 21 <dependency> 22 <groupId>com.qcm</groupId> 23 <artifactId>mvn-ch1</artifactId> 24 <version>0.0.1-SNAPSHOT</version> 25 </dependency> 26 </dependencies> 27 </project>
编写类
1 package com.qcm; 2 3 import com.qcm.HelloMaven; 4 5 public class Hello{ 6 7 public String sayHello(String string){ 8 HelloMaven hm = new HelloMaven(); 9 return hm.sayHello(string); 10 } 11 12 }
测试类:
package com.qcm; import org.junit.*; import static org.junit.Assert.*; public class HelloTest{ @Test public void testHello(){ Hello h = new Hello(); String str = h.sayHello("maven"); System.out.println(str); assertEquals(str,"hello:maven"); } }
然后再cmd 窗口下 进入 mvn-ch2 目录下,运行 编译和 测试 。
标签:
原文地址:http://www.cnblogs.com/quchengming/p/5568067.html