使用MyEclipse构建MAVEN项目 - 我的漫漫程序之旅 - BlogJava
生活随笔
收集整理的這篇文章主要介紹了
使用MyEclipse构建MAVEN项目 - 我的漫漫程序之旅 - BlogJava
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用MyEclipse構(gòu)建MAVEN項(xiàng)目 - 我的漫漫程序之旅 - BlogJava這里用的是MyEclpise的自帶的MAVEN插件。
Maven最好配置成你自己安裝的那個(gè),MyEclipse自帶會有些許Bug。
用nexus代理Maven的中央倉庫,setting.xml的配置文件修改內(nèi)容如下:
<mirrors>
?????<mirror>
??????????<id>nexus</id>
??????????<mirrorOf>*</mirrorOf>
??????????<name>Nexus?Mirror</name>
??????????<url>http://localhost:8081/nexus/content/groups/public</url>
?????</mirror>
??</mirrors>
??
??<profiles>
?????<profile>
??????<id>nexus</id>
??????<repositories>
????????<repository>
??????????<id>central</id>
??????????<url>http://central</url>
??????????<releases><enabled>true</enabled></releases>
??????????<snapshots><enabled>true</enabled></snapshots>
????????</repository>
??????</repositories>
?????<pluginRepositories>
????????<pluginRepository>
??????????<id>central</id>
??????????<url>http://central</url>
??????????<releases><enabled>true</enabled></releases>
??????????<snapshots><enabled>true</enabled></snapshots>
????????</pluginRepository>
??????</pluginRepositories>
????</profile>
??</profiles>
??<activeProfiles>
????<activeProfile>nexus</activeProfile>
??</activeProfiles> http://localhost:8081/nexus/content/groups/public?是倉庫組的地址。
打下MyEclipse新建工程的界面,選擇Maven下的Maven Project,打開如下圖的向?qū)?#xff1a;
這里我們要選中create a simple project。
點(diǎn)擊下一步,填寫GAV相關(guān)內(nèi)容。
點(diǎn)擊完成后,我們就已經(jīng)成功創(chuàng)建了一個(gè)Maven project了。
工程的默認(rèn)目錄結(jié)構(gòu)如下:
所有的Java源文件都要寫在src/main/java目錄下,所有的測試類都要寫在src/test/java下面,這是Maven的默認(rèn)值。
此時(shí),pom.xml里只有默認(rèn)的屬性
<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/maven-v4_0_0.xsd">
??<modelVersion>4.0.0</modelVersion>
??<groupId>com.test</groupId>
??<artifactId>test</artifactId>
??<version>0.0.1-SNAPSHOT</version>
</project>這是最精簡的pom.xml了。
這時(shí)我們加入junit的支持,新建一個(gè)測試類。
在項(xiàng)目上右鍵Maven-Add Dependency,顯示如下界面:
輸入junit加入測試支持類庫。
在src/test/java下新建一個(gè)測試類如下:
package com;import org.junit.Test;public class TestRun{@Testpublic void testA(){System.out.println("test a method ");}@Testpublic void testB(){System.out.println("test b method ");}}右鍵Run As ----- Maven test,進(jìn)行測試,顯示結(jié)果如下:
[INFO]?Scanning?for?projects
[INFO]?????????????????????????????????????????????????????????????????????????
[INFO]?------------------------------------------------------------------------
[INFO]?Building?test?0.0.1-SNAPSHOT
[INFO]?------------------------------------------------------------------------
[INFO]?
[INFO]?---?maven-resources-plugin:2.5:resources?(default-resources)?@?test?---
[debug]?execute?contextualize
[WARNING]?Using?platform?encoding?(GBK?actually)?to?copy?filtered?resources,?i.e.?build?is?platform?dependent!
[INFO]?Copying?0?resource
[INFO]?
[INFO]?---?maven-compiler-plugin:2.3.2:compile?(default-compile)?@?test?---
[INFO]?Nothing?to?compile?-?all?classes?are?up?to?date
[INFO]?
[INFO]?---?maven-resources-plugin:2.5:testResources?(default-testResources)?@?test?---
[debug]?execute?contextualize
[WARNING]?Using?platform?encoding?(GBK?actually)?to?copy?filtered?resources,?i.e.?build?is?platform?dependent!
[INFO]?Copying?0?resource
[INFO]?
[INFO]?---?maven-compiler-plugin:2.3.2:testCompile?(default-testCompile)?@?test?---
[INFO]?Nothing?to?compile?-?all?classes?are?up?to?date
[INFO]?
[INFO]?---?maven-surefire-plugin:2.10:test?(default-test)?@?test?---
[INFO]?Surefire?report?directory:?D:\workspace\test\target\surefire-reports
-------------------------------------------------------
?T?E?S?T?S
-------------------------------------------------------
Running?com.TestRun
test?a?method?
test?b?method?
Tests?run:?2,?Failures:?0,?Errors:?0,?Skipped:?0,?Time?elapsed:?0.071?sec
Results?:
Tests?run:?2,?Failures:?0,?Errors:?0,?Skipped:?0
[INFO]?------------------------------------------------------------------------
[INFO]?BUILD?SUCCESS
[INFO]?------------------------------------------------------------------------
[INFO]?Total?time:?1.847s
[INFO]?Finished?at:?Tue?Sep?11?14:20:59?CST?2012
[INFO]?Final?Memory:?3M/6M
[INFO]?------------------------------------------------------------------------ok,一個(gè)基本的maven項(xiàng)目已經(jīng)構(gòu)建完成。我們還可以將現(xiàn)存的java項(xiàng)目利用myclipse方便的轉(zhuǎn)換成maven project,此部分內(nèi)容我們在下一節(jié)里討論。
來自為知筆記(Wiz)
Maven最好配置成你自己安裝的那個(gè),MyEclipse自帶會有些許Bug。
用nexus代理Maven的中央倉庫,setting.xml的配置文件修改內(nèi)容如下:
<mirrors>
?????<mirror>
??????????<id>nexus</id>
??????????<mirrorOf>*</mirrorOf>
??????????<name>Nexus?Mirror</name>
??????????<url>http://localhost:8081/nexus/content/groups/public</url>
?????</mirror>
??</mirrors>
??
??<profiles>
?????<profile>
??????<id>nexus</id>
??????<repositories>
????????<repository>
??????????<id>central</id>
??????????<url>http://central</url>
??????????<releases><enabled>true</enabled></releases>
??????????<snapshots><enabled>true</enabled></snapshots>
????????</repository>
??????</repositories>
?????<pluginRepositories>
????????<pluginRepository>
??????????<id>central</id>
??????????<url>http://central</url>
??????????<releases><enabled>true</enabled></releases>
??????????<snapshots><enabled>true</enabled></snapshots>
????????</pluginRepository>
??????</pluginRepositories>
????</profile>
??</profiles>
??<activeProfiles>
????<activeProfile>nexus</activeProfile>
??</activeProfiles> http://localhost:8081/nexus/content/groups/public?是倉庫組的地址。
打下MyEclipse新建工程的界面,選擇Maven下的Maven Project,打開如下圖的向?qū)?#xff1a;
這里我們要選中create a simple project。
點(diǎn)擊下一步,填寫GAV相關(guān)內(nèi)容。
點(diǎn)擊完成后,我們就已經(jīng)成功創(chuàng)建了一個(gè)Maven project了。
工程的默認(rèn)目錄結(jié)構(gòu)如下:
所有的Java源文件都要寫在src/main/java目錄下,所有的測試類都要寫在src/test/java下面,這是Maven的默認(rèn)值。
此時(shí),pom.xml里只有默認(rèn)的屬性
<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/maven-v4_0_0.xsd">
??<modelVersion>4.0.0</modelVersion>
??<groupId>com.test</groupId>
??<artifactId>test</artifactId>
??<version>0.0.1-SNAPSHOT</version>
</project>這是最精簡的pom.xml了。
這時(shí)我們加入junit的支持,新建一個(gè)測試類。
在項(xiàng)目上右鍵Maven-Add Dependency,顯示如下界面:
輸入junit加入測試支持類庫。
在src/test/java下新建一個(gè)測試類如下:
package com;import org.junit.Test;public class TestRun{@Testpublic void testA(){System.out.println("test a method ");}@Testpublic void testB(){System.out.println("test b method ");}}右鍵Run As ----- Maven test,進(jìn)行測試,顯示結(jié)果如下:
[INFO]?Scanning?for?projects
[INFO]?????????????????????????????????????????????????????????????????????????
[INFO]?------------------------------------------------------------------------
[INFO]?Building?test?0.0.1-SNAPSHOT
[INFO]?------------------------------------------------------------------------
[INFO]?
[INFO]?---?maven-resources-plugin:2.5:resources?(default-resources)?@?test?---
[debug]?execute?contextualize
[WARNING]?Using?platform?encoding?(GBK?actually)?to?copy?filtered?resources,?i.e.?build?is?platform?dependent!
[INFO]?Copying?0?resource
[INFO]?
[INFO]?---?maven-compiler-plugin:2.3.2:compile?(default-compile)?@?test?---
[INFO]?Nothing?to?compile?-?all?classes?are?up?to?date
[INFO]?
[INFO]?---?maven-resources-plugin:2.5:testResources?(default-testResources)?@?test?---
[debug]?execute?contextualize
[WARNING]?Using?platform?encoding?(GBK?actually)?to?copy?filtered?resources,?i.e.?build?is?platform?dependent!
[INFO]?Copying?0?resource
[INFO]?
[INFO]?---?maven-compiler-plugin:2.3.2:testCompile?(default-testCompile)?@?test?---
[INFO]?Nothing?to?compile?-?all?classes?are?up?to?date
[INFO]?
[INFO]?---?maven-surefire-plugin:2.10:test?(default-test)?@?test?---
[INFO]?Surefire?report?directory:?D:\workspace\test\target\surefire-reports
-------------------------------------------------------
?T?E?S?T?S
-------------------------------------------------------
Running?com.TestRun
test?a?method?
test?b?method?
Tests?run:?2,?Failures:?0,?Errors:?0,?Skipped:?0,?Time?elapsed:?0.071?sec
Results?:
Tests?run:?2,?Failures:?0,?Errors:?0,?Skipped:?0
[INFO]?------------------------------------------------------------------------
[INFO]?BUILD?SUCCESS
[INFO]?------------------------------------------------------------------------
[INFO]?Total?time:?1.847s
[INFO]?Finished?at:?Tue?Sep?11?14:20:59?CST?2012
[INFO]?Final?Memory:?3M/6M
[INFO]?------------------------------------------------------------------------ok,一個(gè)基本的maven項(xiàng)目已經(jīng)構(gòu)建完成。我們還可以將現(xiàn)存的java項(xiàng)目利用myclipse方便的轉(zhuǎn)換成maven project,此部分內(nèi)容我們在下一節(jié)里討論。
來自為知筆記(Wiz)
總結(jié)
以上是生活随笔為你收集整理的使用MyEclipse构建MAVEN项目 - 我的漫漫程序之旅 - BlogJava的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于源码输出,浏览器不解析Html标签
- 下一篇: Vs2013 头文件注释