0% found this document useful (0 votes)
80 views

Maven Quick Reference Card

Maven Quick Reference

Uploaded by

Tr Tzara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Maven Quick Reference Card

Maven Quick Reference

Uploaded by

Tr Tzara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Maven2 Reference card

Starting Maven
mvn plugin:target [-Doption1 -Doption2 . . . ] mvn help mvn -X ... Prints debugging output, very useful to diagnose

Creating a new Project (jar)


mvn archetype:create \ -DgroupId=Arti act!roup -Darti actId=Arti actID Example: mvn archetype:create \ -DgroupId=de. ocu"dv.#c" -Darti actId=ne$-app Creates a new Project Directory new-app with pac age structure de. ocu"dv.#c"! "ame of the pac aged jar will be ne$-app-ver"ion.%ar

Creating a new Project (war)


mvn archetype:create \ -DgroupId=Arti act!roup -Darti actId=Arti actID \ -DarchetypeArti actId=maven-archetype-$e#app Example: mvn archetype:create \ -DgroupId=de. ocu"dv.#c" -Darti actId=ne$-$e#app \ -DarchetypeArti actId=maven-archetype-$e#app Creates a new Directory new-webapp with pac age structure de!focusdv!bcs! "ame of the pac aged war will be new-app-version!war #tandard Project #tructure &ne$-app&pom.'ml maven$ project %le &ne$-app&"rc& &ne$-app&"rc&main&%ava& &ne$-app&"rc&te"t&%ava& &ne$-app&"rc&main&re"ource"& &ne$-app&"rc&te"t&re"ource"& &ne$-app&target&cla""e"& &ne$-app&target&te"t-cla""e"& &ne$-app&target&... &ne$-$e#app&"rc&main&$e#app #ources 'ava sources 'ava unit tests 'ava classpath resources (esources for unit-tests compiled classes compiled test classes other plugins) output root of webapp

Compiling
mvn compile

Running Unit Tests


mvn te"t compiles and runs unit tests

Packaging (jar, war)


mvn clean pac(age compiles, runs unit tests and pac ages the artifact *clean ma es sure there are no unwanted %les in the pac age+

Installing Arti act in !ocal Repositor"


mvn clean in"tall compiles, runs unit tests, pac ages and installs the artifact in the local repository i!e! ,userhome,&!m$&repository&

Installing Arti act in Remote Repositor"


mvn clean deploy compiles, runs unit tests, pac ages and installs the artifact in the remote repository!

Installing #r$Part" jar


mvn in"tall:in"tall- ile \ -D ile= oo.%ar \ -DgroupId=org. oo"o t \ -Darti actId= oo \ -Dver"ion=1.2.) \ -Dpac(aging=%ar

Install #r$Part" jar to Remote Repositor"


mvn deploy:deploy- ile \ -DgroupId=common"-collection" \ -Darti actId=collection"-generic -Dver"ion=*.+ \ -Dpac(aging=%ar -D ile=collection"-generic-*.+.%ar \ -Drepo"itoryId= ocu"-repo"itory \ -Durl="cp:&&ho"t&home&mvn&pu#lic,html&repo"itory

Cleaning Up
mvn clean

Creating %clipse Project Structure


mvn eclip"e:eclip"e -f using the eclipse plugin from update-site http:&&m2eclip"e.codehau".org remove the generated dependencies from project! .aven Project %le *pom.'ml+ .inimal pom.'ml is created with mvn archetype:create *see above+!

A$$ing &epen$encies
-dependencie". -dependency. -groupId.%unit-&groupId. -arti actId.%unit-&arti actId. -ver"ion.)./.1-&ver"ion. -"cope.te"t-&"cope. -&dependency. -dependency. -groupId.org."pring rame$or(-&groupId. -arti actId."pring-&arti actId. -ver"ion.1.2.0-&ver"ion. -&dependency. ... -&dependencie". /ecause of -"cope.te"t-&"cope., junit will not be included in %nal pac aging!

A$$ing &evelopers
-developer". -developer. -id.1aier-&id. -name.2an" 1aier-&name. -email.han".#aier::at:: ocu"-dv.de-&email. -organi3ation. ocu" D4 !m#2-&organi3ation. -role". -role.Developer-&role. -&role". -&developer. ... -&developer".

Setting Compiler 'ersion


-#uild. -plugin". -plugin. -arti actId.maven-compiler-plugin-&arti actId. -con iguration. -"ource.1.5-&"ource. -target.1.5-&target. -&con iguration. -&plugin. ... -&plugin". -&#uild.

Creating Assem(lies
0o pac age the artifact use the following lines in the !pom-%le: -plugin. -arti actId.maven-a""em#ly-plugin-&arti actId. -con iguration. -de"criptor".

-de"criptor."rc&main&a""em#ly& oo-dep.'ml-&de"criptor. -de"criptor."rc&main&a""em#ly& oo.'ml-&de"criptor. -&de"criptor". -&con iguration. -&plugin. "rc&main&a""em#ly is the maven standard directory for assemblies! 0he %rst assembly descriptor pac ages all dependencies into one jar: -a""em#ly. -id.dep-&id. - ormat". - ormat.%ar-& ormat. -& ormat". -include1a"eDirectory. al"e-&include1a"eDirectory. -dependency6et". -dependency6et. -outputDirectory.-&outputDirectory. -unpac(.true-&unpac(. -"cope.runtime-&"cope. -e'clude". -e'clude.%unit:%unit-&e'clude. -&e'clude". -&dependency6et. -&dependency6et". -&a""em#ly. 0he second descriptor pac ages the program: -a""em#ly. -id.#in-&id. - ormat". - ormat.3ip-& ormat. -& ormat". - ile6et". - ile6et. -directory."rc&main&a""em#ly& ile"-&directory. -outputDirectory.-&outputDirectory. -include". -include.77&7.#at-&include. -include.77&native&77-&include. -include.77&7.propertie"-&include. -&include". -& ile6et. - ile6et. -directory.target-&directory. -outputDirectory.-&outputDirectory. -include". -include.7.%ar-&include. -&include". -& ile6et. -& ile6et". -&a""em#ly.

#upplementary %les in this example are in "rc&main&a""em#ly& ile". 0his includes the program starter *!bat+, native libraries *&native+ and Properties %les! Pac aging is invo ed by: mvn a""em#ly:a""em#ly

Integration test) &eplo"ing *e(+App to Tomcat


1sing Cargo http:&&cargo!codehaus!org& -#uild. -plugin". ... -plugin. -groupId.org.codehau".cargo-&groupId. -arti actId.cargo-maven2-plugin-&arti actId. -e'ecution". -e'ecution. -id.tomcat-e'ecution-&id. -pha"e.pac(age-&pha"e. -goal". -goal."tart-&goal. -&goal". -con iguration. -$ait.true-&$ait. -container. -containerId.tomcat5'-&containerId. -3ip8rlIn"taller. -url. http:&&$$$.apache.org&...&%a(arta-tomcat.3ip -&url. -in"tallDir.9:in"tallDir;-&in"tallDir. -&3ip8rlIn"taller. -&container. -con iguration. -dir.9:pro%ect.#uild.directory;&tomcat5'&-&dir. -&con iguration. -&con iguration. -&e'ecution. -&e'ecution". -&plugin. -&plugin". -&#uild. 0hen execute in project directory: mvn -X integration-te"t 0he war-%le will built, tested and pac aged! 0hen tomcat will be downloaded, installed and started with the war-%le of the project deployed to the server! -f you want to use jetty2 *already embedded, fast startup+ use: mvn cargo:"tart *Press Ctrl-C to stop+

Instant ,ot $eplo"ment or *e( &evelopment


3s a web developer you want the container to restart the 4eb-3pp instantly if changes occur! 0he 'etty5 Plugin delivers that functionality: -plugin. -groupId.org.mort#ay.%etty-&groupId. -arti actId.maven-%etty0-plugin-&arti actId. -con iguration. -"canInterval6econd".1+-&"canInterval6econd". -&con iguration. -&plugin. 0hen start 'etty with mvn %etty0:run

Setting Source Co$e Control S"stem


-"cm. -developer<onnection. "cm:"vn:http":&&"vnho"t.net&"vnroot&trun(&ne$-app -&developer<onnection. -&"cm. -#uild. -plugin". -plugin. -arti actId.maven-relea"e-plugin-&arti actId. -con iguration. -tag1a"e.http":&&"vnho"t.net&"vnroot&tag"-&tag1a"e. -&con iguration. -&plugin. ... -&plugin". -&#uild.

Using internal Repositories


0his assumes that a machine myhost exists with a con%gured and running 4eb-#erver and ##6#erver -repo"itorie". -repo"itory. -id. ocu"-repo"itory-&id. -name.=ocu" 1<6 >epo"itory-&name. -url.http:&&myho"t&mvn&repo"itory-&url. -&repo"itory. -&repo"itorie". -di"tri#ution?anagement. -repo"itory. -id. ocu"-repo"itory-&id. -name.=ocu" 1<6 >epo"itory-&name. -url."cp:&&myho"t&var&$$$&mvn&repo"itory&-&url. -&repo"itory. -&di"tri#ution?anagement.

Using Pro-les (" .S


-n this example we want to use the 7inux #40 7ibraries on 7inux and the 4indows libs on 4indows: -pro ile". -pro ile. -id.$indo$"-&id. -activation. -o". - amily.$indo$"-& amily. -&o". -&activation. -dependencie". -dependency. -groupId."$t-&groupId. -arti actId."$t-$in)2-&arti actId. -ver"ion.).1.1-&ver"ion. -&dependency. -&dependencie". -&pro ile. -pro ile. -id.uni'-&id. -activation. -o". - amily.uni'-& amily. -&o". -&activation. -dependencie". -dependency. -groupId."$t-&groupId. -arti actId."$t-linu'-gt(-&arti actId. -ver"ion.).1.1-&ver"ion. -&dependency. -&dependencie". -&pro ile. -&pro ile".

'ersioning
8eep the 9erision of your P:. artifact in the form version-#"3P#6:0 until you release! .avens release plugin then removes the -#"3P#6:0 sux!

Preparing Releases
.a e sure, the #C. settings in the P:. are correct and all changes are committed to the #C.! 0hen execute mvn -Du"ername=86@> -Dpa""$ord=AA66 relea"e:prepare /efore issuing the above command use it with -Ddry>un=true %rst "ote: 0his command will erase any -activation. tags in con%gured build pro%les in the pom.'ml

Per orming Releases


mvn -A proBle -Drelea"e:per orm Chec s out the released version from tag in repository, builds, tests, pac ages and installs pac age, javadoc and sources in repository! 3s preparing the release removes activation tags from build pro%les, it is necessary to supply the pro%le or the release will fail!

Copyright by 6ans /aier *hansbaier;web!de+, <ocus D9 =mb6, =ermany, 7icense: Public domain

You might also like