亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Maven教程初級篇02:pom.xml配置初步

系統 2084 0

?

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

你應該可以看到如下結果:

Maven教程初級篇02:pom.xml配置初步

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教程初級篇02:pom.xml配置初步


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 天天操夜夜操视频 | 亚洲第一综合色 | 九九久久国产精品免费热6 九九久久精品 | 国产在线拍揄自揄视频不卡99 | 亚洲欧洲精品视频在线观看 | avav国产| 五月天色中色 | 久久亚洲人成国产精品 | 欧美日韩中文国产一区二区三区 | 色资源在线 | 日本成人一区二区 | 亚洲无限看 | 亚洲午夜在线观看 | 亚洲视频在线免费看 | 国产片一级aaa毛片视频 | 国产欧美在线视频免费 | 国产精品免费看久久久 | 欧美日本高清视频在线观看 | 毛片大全在线 | 亚洲欧美日韩网站 | 久久福利在线 | 色综七七久久成人影 | 亚洲午夜久久久精品影院视色 | 欧美久久亚洲精品 | 一级毛片在线 | 国产福利在线免费观看 | 草逼网站 | 国产91在线 | 欧美 | julia紧身裙中文字幕在线看 | 四虎影视在线影院www | 久久综合狠狠综合久久97色 | 久久国产精品-久久精品 | 综合网在线观看 | 亚洲精品一区二区在线播放 | 亚洲婷婷在线视频 | 911视频免费 | 欧洲成人在线视频 | 夜夜骑日日 | 夜夜爽天天狠狠九月婷婷 | 日韩美女va在线毛片免费知 | 羞羞视频免费观看网站 |