Maven项目的构建与测试
在上一节中,我们介绍了如何使用 archetype 创建 Maven 项目,接下来我们介绍如何构建和测试这个项目。
构建项目
查看 helloMaven 项目的 pom.xml 文件,配置如下。
<project xmlns="http://maven.apache网站站点" rel="nofollow" />
mvn clean package
令执行结果如下:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< net.biancheng.www:helloMaven >--------------------
[INFO] Building helloMaven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ helloMaven ---
[INFO] Deleting D:\maven\helloMaven\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloMaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven\helloMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloMaven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\maven\helloMaven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloMaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven\helloMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloMaven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\maven\helloMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ helloMaven ---
[INFO] Surefire report directory: D:\maven\helloMaven\target\surefire-reports
Downloading from central: https://repo.maven.apache网站站点" rel="nofollow" />
图1:target 目录
说明:
Maven 令中包含了两个令:clean 和 package,其中 clean 负责清理 target 目录,package 负责将项目构建并打包输出为 jar 文件。
classes:源代码编译后存放在该目录中。
test-classes:测试源代码编译后并存放在该目录中。
surefire-reports:Maven 运行测试用例生成的测试报告存放在该目录中。
helloMaven-1.0-SNAPSHOT.jar:Maven 对项目进行打包生成的 jar 文件。
打开令控制台,跳转到 D:\maven\helloMaven\target\classes 目录,执行 Java 令
java net.biancheng.www.App
执行结果如下。
Hello World!
测试项目
下面我们介绍如何在 Maven 项目中添加其他的 Java 文件,并进行测试。打开 D:\maven\helloMaven\src\main\java\net\biancheng\www 文件夹,在其中创建一个名为 Util.java 的文件。
package net.biancheng.www;
/**
* Maven 项目中添加的自定义java类
*
* @author 编程帮 www.biancheng网站站点" rel="nofollow" />
package net.biancheng.www;
/**
* @author 编程帮 www.biancheng网站站点" rel="nofollow" />
mvn clean compile
令执行结果如下。
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< net.biancheng.www:helloMaven >--------------------
[INFO] Building helloMaven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ helloMaven ---
[INFO] Deleting D:\maven\helloMaven\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloMaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven\helloMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloMaven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\maven\helloMaven\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.853 s
[INFO] Finished at: 2021-03-03T09:26:29+08:00
[INFO] ------------------------------------------------------------------------
编译成功后,跳转到 D:\maven\helloMaven\target\classes 目录下,执行以下 Java 令。
java net.biancheng.www.App
执行结果如下。
编程帮欢迎您,网址:www.biancheng网站站点" rel="nofollow" />
- 随机文章
- 核心危机(核心危机魔石合成攻略)
- 饿了么红包怎么用(饿了么红包怎么用微信支付)
- 儿童教育文章(儿童教育)
- 光遇花手先祖位置(安卓光遇手花先祖)
- 广州4a广告公司(广州4a广告公司创意总监年薪)
- 抖音卡(抖音卡顿怎么解决)
- xboxones(xboxone手柄怎么配对主机)
- 兵马俑(兵马俑介绍和历史背景)
- 陈武简历
- 帆船比赛(帆船比赛视频)
- 海猫鸣泣之时游戏(海猫鸣泣之时游戏在哪玩)
- 韩国媳妇和小雪(韩国媳妇和小雪的父亲工资是多少)
- 地球日主题(2020年世界地球日主题)
- 和柳亚子(和柳亚子先生于田)
- 冰客(冰客果汁)
- yy魔兽(yy魔兽世界)
- 国外成人游戏(国外成人游戏注册需要visa信用卡)
- 充值卡代理(充值卡代理加盟)
- 郭妮小说(恶魔的法则郭妮小说)
- 东天目山(东天目山景区)
- 大松电饭煲(美的大松电饭煲)
- 疯狂填字(疯狂填字5)
- 点对点短信息(点对点短信息费是什么意思)
- 观音普门品(观音普门品念诵全文)
- 河北省大运会(河北省大运会时间)
- 哈利波特官网(哈利波特官网在哪里)
- 骇客神条(骇客神条怎么辨别真假)
- 杜星霖(杜星霖图片)
- 查传倜(查传倜个人生活)
- 广州晓港公园(广州晓港公园正门图片)

