您的位置:首页 > 其它

Maven 初学(一)基本概念

2013-10-15 08:57 183 查看
Pom中有三个主要元素

Groupid,artifactid,version

goupid是一个组织唯一的标识例如com.ibm.www

artifactid是一个工程呢IDibm-project

version代表一个版本例如com.ibm.www.ibm-project.1.0

maven执行一个目标(goal)有以下几个步骤

prepare-resources资源的拷贝

compile源代码拷贝阶段

package创建jar/war包阶段

install安装包到本地或者远程库中

mvncleandependency:copy-dependenciespackage


clean首先被执行,

然后dependency:copy-dependencies被执行

然后是package被执行

clean的Lifecycle

pre-clean

clean

post-clean


默认buildLifecycle

validate验证工程是否正确,所有必要的信息是否有效

LifecyclePhaseDescription
validateValidateswhetherprojectiscorrectandallnecessaryinformationisavailabletocompletethebuildprocess.
initializeInitializesbuildstate,forexamplesetproperties
generate-sourcesGenerateanysourcecodetobeincludedincompilationphase.
process-sourcesProcessthesourcecode,forexample,filteranyvalue.
generate-resourcesGenerateresourcestobeincludedinthepackage.
process-resourcesCopyandprocesstheresourcesintothedestinationdirectory,readyforpackagingphase.
compileCompilethesourcecodeoftheproject.
process-classesPost-processthegeneratedfilesfromcompilation,forexampletodobytecodeenhancement/optimizationonJavaclasses.
generate-test-sourcesGenerateanytestsourcecodetobeincludedincompilationphase.
process-test-sourcesProcessthetestsourcecode,forexample,filteranyvalues.
test-compileCompilethetestsourcecodeintothetestdestinationdirectory.
process-test-classesProcessthegeneratedfilesfromtestcodefilecompilation.
testRuntestsusingasuitableunittestingframework(Junitisone).
prepare-packagePerformanyoperationsnecessarytoprepareapackagebeforetheactualpackaging.
packageTakethecompiledcodeandpackageitinitsdistributableformat,suchasaJAR,WAR,orEARfile.
pre-integration-testPerformactionsrequiredbeforeintegrationtestsareexecuted.Forexample,settinguptherequiredenvironment.
integration-testProcessanddeploythepackageifnecessaryintoanenvironmentwhereintegrationtestscanberun.
post-integration-testPerformactionsrequiredafterintegrationtestshavebeenexecuted.Forexample,cleaninguptheenvironment.
verifyRunanycheck-upstoverifythepackageisvalidandmeetsqualitycriterias.
installInstallthepackageintothelocalrepository,whichcanbeusedasadependencyinotherprojectslocally.
deployCopiesthefinalpackagetotheremoterepositoryforsharingwithotherdevelopersandprojects.
localRepository本地库

可以在settings文件中设置本地库位置

<settingsxmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd"><localRepository>C:/MyLocalRepository</localRepository>
</settings>

CentralRepository中心库

maven在本地库中不能找到依赖的时候,就回去中心库中寻找

http://repo1.maven.org/maven2/

RemoteRepository远程库

<projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.companyname.common-lib</groupId>
<artifactId>common-lib</artifactId>
<version>1.0.0</version>
</dependency>
<dependencies>
<repositories>
<repository>
<id>companyname.lib1</id>
<url>http://download.companyname.org/maven2/lib1</url>
</repository>
<repository>
<id>companyname.lib2</id>
<url>http://download.companyname.org/maven2/lib2</url>
</repository>
</repositories>
</project>

使用archetype插件创建工程

C:\MVN>mvnarchetype:generate
-DgroupId=com.companyname.bank
-DartifactId=consumerBanking
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false


参考自:http://www.tutorialspoint.com/maven/maven_quick_guide.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: