Maven教程初级篇02:pom.xml配置初步
1. 创建项目并更改项目基本配置信息
在命令行下运行如下命令创建一个项目:
1 |
mvn archetype:create -DgroupId=net.jianxi.tutorials |
2 |
-DartifactId=numopers |
3 |
-DpackageName=net.jianxi.tutorials |
4 |
-Dversion= 1.0 |
进入到numopers目录,打开pom.xml,该文件内容如下:
<
project
xmlns
="http://maven.apache.org/POM/4.0.0"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
> <
modelVersion
>
4.0.0
</
modelVersion
> <
groupId
>
net.jianxi.tutorials
</
groupId
> <
artifactId
>
numopers
</
artifactId
> <
version
>
1.0
</
version
> <
packaging
>
jar
</
packaging
> <
name
>
numopers
</
name
> <
url
>
http://maven.apache.org
</
url
> <
properties
> <
project.build.sourceEncoding
>
UTF-8
</
project.build.sourceEncoding
> </
properties
> <
dependencies
> <
dependency
> <
groupId
>
junit
</
groupId
> <
artifactId
>
junit
</
artifactId
> <
version
>
3.8.1
</
version
> <
scope
>
test
</
scope
> </
dependency
> </
dependencies
> </
project
>
其中:
- groupId: 通常为项目的顶级包名。
- artifactId: 通常为项目名
- version:项目的版本号,在开发的不同阶段,你需要更改这个版本号。
- packaging:项目发布时的打包类型。比如对于普通Java程序打包为jar文件;对于Java web项目则打包为war文件。
- name:通常也是项目名
- url:项目的主页。
2. 添加源代码
在你的项目的src\main\java\net\jianxi\tutorials目录下,删除原有的App.java, 添加一个新的Java源文件: NumOpers.java, 其源代码如下:
01 |
package net.jianxi.tutorials; |
02 |
03 |
public class NumOpers |
04 |
{ |
05 |
public int add( int i, int j) { |
06 |
return i + j; |
07 |
} |
08 |
|
09 |
public int minus( int i, int j) { |
10 |
return i - j; |
11 |
} |
12 |
} |
之后可运行如下命令进行编译:
mvn compile
你应该可以看到如下结果:
3. 添加JUnit 4.x单元测试类
在你的项目的src\test\java\net\jianxi\tutorials目录下,删除原有的AppTest.java, 添加一个新的Java源文件: NumOpersTest.java, 其源代码如下:
01 |
package net.jianxi.tutorials; |
02 |
03 |
import org.junit.* ; |
04 |
import static org.junit.Assert.* ; |
05 |
06 |
public class NumOpersTest { |
07 |
NumOpers no = new NumOpers(); |
08 |
09 |
@Test |
10 |
public void testAdd() { |
11 |
assertEquals(no.add( 3 , 5 ), 8 ); |
12 |
} |
13 |
|
14 |
@Test |
15 |
public void testMinus() { |
16 |
assertEquals(no.minus( 10 , 5 ), 5 ); |
17 |
} |
18 |
} |
4. 配置pom.xml限定JDK版本号为5, 并支持JUnit 4.7
修改后的pom.xml文件为:
代码 <
project
xmlns
="http://maven.apache.org/POM/4.0.0"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
> <
modelVersion
>
4.0.0
</
modelVersion
> <
groupId
>
net.jianxi.tutorials
</
groupId
> <
artifactId
>
numopers
</
artifactId
> <
version
>
1.0
</
version
> <
packaging
>
jar
</
packaging
> <
name
>
numopers
</
name
> <
url
>
http://bluesfeng.javaeye.com
</
url
> <
build
> <
plugins
> <
plugin
> <
artifactId
>
maven-compiler-plugin
</
artifactId
> <
configuration
> <
source
>
1.5
</
source
> <
target
>
1.5
</
target
> </
configuration
> </
plugin
> </
plugins
> </
build
> <
properties
> <
project.build.sourceEncoding
>
UTF-8
</
project.build.sourceEncoding
> </
properties
> <
dependencies
> <
dependency
> <
groupId
>
junit
</
groupId
> <
artifactId
>
junit
</
artifactId
><
version
>
4.7
</
version
><
scope
>
test
</
scope
> </
dependency
> </
dependencies
> </
project
>
现在你可以运行一下命令来自动测试了:
mvn test
如果测试通过,你可以看到如下结果:
Maven教程初级篇02:pom.xml配置初步的更多相关文章
- Maven 教程(16)— pom.xml 文件详解
原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79733577 <project xmlns="http://ma ...
- Thrift教程初级篇——thrift安装环境变量配置第一个实例
前言: 因为项目需要跨语言,c++客户端,web服务端,远程调用等需求,所以用到了RPC框架Thrift,刚开始有点虚,第一次接触RPC框架,后来没想到Thrift开发方便上手快,而且性能和稳定性也不 ...
- maven 配置篇 之pom.xml
http://www.blogjava.net/zyl/archive/2006/12/30/91055.html http://maven.apache.org/pom.html的翻译. m ...
- Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):4、Maven项目转换与pom.xml配置
文章目录: Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):1.JIRA账号注册 Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):2.PGP ...
- pom.xml 配置maven私服
1.pom.xml 配置maven私服 <repositories> <repository> <id>caf_repositories& ...
- Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):3、Maven独立插件安装与settings.xml配置
文章目录: Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):1.JIRA账号注册 Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):2.PGP ...
- NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者
NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者 作者: raindy 来源:http://bbs.hanzify.org/index.php?showtopic=30029 时间: ...
- pom.xml配置,针对mvn clean install -P参数(环境参数)打包
pom.xml配置,针对mvn clean install -P参数(环境参数)打包 比如你有2个环境,一个dev,一个prod, 然后你在mvn打包的时候,可以通过-P来打包,是打dev包,还是pr ...
- Maven-SSM项目pom.xml配置以及springmvc配置以及mybatis配置及web.xml配置
一.Maven本地仓库的pom.xml配置 (全部是mysql数据库) <project xmlns="http://maven.apache.org/POM/4.0.0" ...
随机推荐
- android编译错误“OnClickListener cannot be resolved to a type”
在android代码编译时可能会出现如下错误: 部分代码: <span style="font-size:18px;">public void onCreate(Bun ...
- 使用newScheduledThreadPool来模拟心跳机制
(使用newScheduledThreadPool来模拟心跳机制) 1 public class HeartBeat { 2 public static void main(String[] args ...
- Python index()方法
Python index()方法 Python 字符串 描述 Python index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否 ...
- SQL:两种获取时间类型日期部分的方法
参考网址:http://www.w3school.com.cn/sql/sql_dates.asp. ), PassedDate, ), , PassedDate), )
- SharePoint JavaScript API in application pages
前言 最近,在SharePoint 应用程序页中写JavaScript API,进行一些数据交互.其实,很简单的事情却遇到了问题,记录一下,希望能对遇到类似问题的人以帮助. 引用JavaScript ...
- 真实的人类第三季/全集Humans迅雷下载
Channel 4及AMC宣布续订<真实的人类 Humans>第三季,下季为8集:新季拍摄将在秋季开始,主要角色会回归.该剧设定在机器人Synth被繁忙都市人广泛使用的世界,呈现人类与机器 ...
- wdcp支持两种安装方式
v3.2版本已发布,支持多PHP版本共存共用,支持SSL证书,更多可看论坛 v3版讨论区 更多安装说明请看 http://www.wdlinux.cn/bbs/thread-57643-1-1.htm ...
- [wxWidgets]_[0基础]_[不常见但有用的类wxStandardPaths]
场景: 1.wxStandardPaths 用来获取各种系统路径.能够用于存放app的配置数据.比方文档文件夹,appData等. 代码: #include "wx/wxprec.h&q ...
- PostgreSQL入门,PostgreSQL和mysql
PostgreSQL被誉为“世界上功能最强大的开源数据库”,是以加州大学伯克利分校计算机系开发的POSTGRES 4.2为基础的对象关系型数据库管理系统. PostgreSQL支持大部分 SQL标准并 ...
- Keras教程
In this step-by-step Keras tutorial, you’ll learn how to build a convolutional neural network in Pyt ...