一.在pom.xml文件夹导入junit包
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apche.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.hello</groupId>
<artifactId>ch01-maven</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

二.编写Java文件

package com.hello;
public class HelloMaven{
public int add(int n1,int n2){
return n1+n2;
}
public static void main(String args[]){
HelloMaven hello = new HelloMaven();
int res = hello.add(10,20);
System.out.println("10+20="+res);
}
}

三.使用Maven将执行java的编写

在根目录下hello下,使用dos窗口编写

mvn compile

编译成功,出现target目标文件

四.编译测试程序

在test文件夹下,编写

package com.hello;
import org.junit.Assert;
import org.junit.Test;
public class TestHello{
@Test
public void testAdd(){
System.out.println("test result....");
HelloMaven hello = new HelloMaven();
int res = hello.add(10,20);
Assert.assertEquals(30,res);
}
}

用来测试

五.执行测试

mvn test

六.打包

mvn package

 会在target目录下出现一个jar包文件

七.安装

mvn install

安装到私服仓库

八.发布

mvn deploy

 

posted on 2021-04-15 23:17  文种玉  阅读(242)  评论(0编辑  收藏  举报