Professional Documents
Culture Documents
Maven Quick Reference Card
Maven Quick Reference Card
Prints help debugging output, very useful to diagnose Creating a new Project (jar)
mvn archetype:create -DgroupId=Artifact Group -DartifactId=Artifact ID
Example:
mvn archetype:create -DgroupId=de.focusdv.bcs -DartifactId=new-app
Creates a new Project irectory new-app with pac!age structure de.focusdv.bcs" #ame of the pac!aged jar will be new$app$version"jar Creating a new Project (war)
mvn archetype:create -DgroupId=Artifact Group -DartifactId=Artifact ID -Darchetype rtifactId=maven-archetype-webapp
Example:
mvn archetype:create -DgroupId=de.focusdv.bcs -DartifactId=new-webapp -Darchetype rtifactId=maven-archetype-webapp
Creates a new irectory new-webapp with pac!age structure de.focusdv.bcs" #ame of the pac!aged war will be new$app$version"war Standard Project Structure directory %new$app%pom"xml %new$app%src% %new$app%src%main%java% %new$app%src%test%java% %new$app%src%main%resources% %new$app%src%test%resources% %new$app%target%classes% %new$app%target%test$classes% %new$app%target%dots description maven& project file Sources 'ava source tree 'ava unit tests 'ava classpath resources (esources for unit$tests compiles classes compiles test classes other plugins) output
root of webapp
generates a code$coverage report for the tests" *t only wor!s, if the pom"xml is configured as follows:
!"pro#ect$ % !build$ !plugins$ % !plugin$ !groupId$org.codehaus.mo#o!"groupId$ !artifactId$cobertura-maven-plugin!"artifactId$ !e&ecutions$ !e&ecution$ !goals$ !goal$clean!"goal$ !"goals$ !"e&ecution$ !"e&ecutions$ !"plugin$ % !"plugins$ !"build$ % !reporting$ !plugins$ !plugin$ !groupId$org.codehaus.mo#o!"groupId$ !artifactId$cobertura-maven-plugin!"artifactId$ !"plugin$ !"plugins$ !"reporting$ % !"pro#ect$
compiles, runs unit tests and pac!ages the artifact +clean ma!es sure there are no unwanted files in the pac!age, Installing $rtifact in %ocal Repository
mvn clean install
compiles, runs unit tests, pac!ages and installs the artifact in the local repository" +User Home Directory%"m&%repository%, Installing &rdParty jar in local Repository
mvn install:install-file -Dfile=foo.#ar -DgroupId=org.foosoft -DartifactId=foo -Dversion=(.).* -Dpac'aging=#ar
Cleaning p
mvn clean
*f using the eclipse plugin from update$site http:%%m&eclipse"codehaus"org remove the generated dependencies from project" Maven Project file (pom()ml) -inimal pom"xml is created with
mvn archetype:create
!id$-aier!"id$ !name$.ans -aier!"name$ !email$hans.baier::at::focus-dv.de!"email$ !organi/ation$focus D0 1mb.!"organi/ation$ !roles$ !role$Developer!"role$ !"roles$ !"developer$ % !"developers$
Creating $ssem,lies /o pac!age the artifact use the following lines in the "pom$file:
!plugin$ !artifactId$maven-assembly-plugin!"artifactId$ !configuration$ !descriptors$ !descriptor$src"main"assembly"foo-dep.&ml!"descriptor$ !descriptor$src"main"assembly"foo.&ml!"descriptor$ !"descriptors$ !"configuration$ !"plugin$
src%main%assembly is the maven standard directory for assemblies" /he first assembly descriptor pac!ages all dependencies into one jar:
!assembly$ !id$dep!"id$ !formats$ !format$#ar!"format$ !"formats$ !include-aseDirectory$false!"include-aseDirectory$ !dependency3ets$ !dependency3et$ !outputDirectory$!"outputDirectory$ !unpac'$true!"unpac'$ !scope$runtime!"scope$ !e&cludes$
Supplementary files in this example are in src%main%assembly%files" /his includes the program starter +"bat,, native libraries +%native, and Properties files" Pac!aging is invo!ed by:
mvn assembly:assembly
sing Profiles Profiles enable different versions of a project to be build, or adapting to different environments by an option on the command line" Profiles can modify almost all dependencies, plugins and settings in the pom.xml" *n cockpit-model they are used to generate a restricted demo$version and a release$ version li!e that:
!profiles$ !profile$ !id$release-profile!"id$ !dependencies$ !dependency$ !groupId$swt!"groupId$ !artifactId$swt-win*)!"artifactId$ !version$*.).(!"version$ !"dependency$ !"dependencies$ !build$ !filters$ !filter$src"main"filters"release0ersion.properties!"filter$
!"filters$ !"build$ !"profile$ !profile$ !id$demo!"id$ !dependencies$ !dependency$ !groupId$swt!"groupId$ !artifactId$swt-win*)!"artifactId$ !version$*.).(!"version$ !"dependency$ !"dependencies$ !build$ !filters$ !filter$src"main"filters"demo0ersion.properties!"filter$ !"filters$ !"build$ !"profile$ % !"profiles$
0ere the release-profile uses the windows library of S1/ +since our customers) platform is windows +li!e it or not""",, and substitutes the resources files) placeholders with the variables in releaseVersion.properties" /he demo$profile is almost the same except it uses demoVersion.properties for filtering" sagemvn -5release-profile clean assembly:assembly
or
mvn -5demo clean assembly:assembly
sing Profiles ,y .S *n this example we want to use the 2inux S1/ 2ibraries on 2inux and the 1indows libs on 1indows:
!profiles$ !profile$ !id$windows!"id$ !activation$ !os$ !family$windows!"family$ !"os$ !"activation$ !dependencies$ !dependency$ !groupId$swt!"groupId$ !artifactId$swt-win*)!"artifactId$ !version$*.(.(!"version$ !"dependency$ !"dependencies$ !"profile$ !profile$ !id$uni&!"id$ !activation$ !os$ !family$uni&!"family$ !"os$ !"activation$ !dependencies$
+ersioning 3eep the 4erision of your P5- artifact in the form version$S#6PS05/ until you release" -avens release plugin then removes the $S#6PS05/ suffix" sing internal Repositories /his assumes that a machine myhost exists with a configured and running 1eb$Server and SS0$ Server
!repositories$ !repository$ !id$focus-repository!"id$ !name$7ocus -63 8epository!"name$ !url$http:""myhost"mvn"repository!"url$ !"repository$ !"repositories$ !distribution9anagement$ !repository$ !id$focus-repository!"id$ !name$7ocus -63 8epository!"name$ !url$scp:""myhost"var"www"mvn"repository"!"url$ !"repository$ !"distribution9anagement$
compiles, runs unit tests, pac!ages and installs the artifact in the remote repository" Install &rdParty jar to Remote Repository
mvn deploy:deploy-file -DgroupId=commons-collections -DartifactId=collections-generic -Dversion=:.; -Dpac'aging=#ar -Dfile=collections-generic-:.;.#ar -DrepositoryId=focus-repository -Durl=scp:""host"home"mvn"public<html"repository
Preparing Releases -a!e sure, the SC- settings in the P5- are correct and all changes are committed to the SC-" /hen execute
mvn -Dusername=USER -Dpassword=PASS release:prepare
.efore issuing the above command use it with -DdryRun=true first tags in configured build profiles in the pom"xml Performing Releases
mvn -5 profile -Drelease:perform
Chec!s out the released version from tag in repository, builds, tests, pac!ages and installs pac!age, javadoc and sources in repository" 6s preparing the release removes activation tags from build profiles, it is necessary to supply the profile or the release will fail"
/e,0*evelopment
!container$ !containerId$tomcat2&!"containerId$ !/ip=rlInstaller$ !url$!http:""www.apache.org"..."#a'arta-tomcat./ip$!"url$ !installDir$>?installDir@!"installDir$ !"/ip=rlInstaller$ !"container$ !configuration$ !dir$>?pro#ect.build.directory@"tomcat2&"!"dir$ !"configuration$ !"configuration$ !"e&ecution$ !"e&ecutions$ !"plugin$ !"plugins$ !"build$
/he war$file will built, tested and pac!aged" /hen tomcat will be downloaded, installed and started with the war$file of the project deployed to the server" *f you want to use jetty7 +already embedded, fast startup, use:
mvn cargo:start
+Press Ctrl$C to stop, .nline we,0development wit1 2etty plugin 6dd -aven$Plugin to pom"xml:
!plugins$ % !plugin$ !groupId$org.mortbay.#etty!"groupId$ !artifactId$maven-#etty,-plugin!"artifactId$ !configuration$ !scanInterval3econds$(;!"scanInterval3econds$ !"configuration$ !"plugin$ % !"plugins$
.nline we,0development and automatic deployment wit1 tomcat plugin 6dd -aven$Plugin to pom"xml:
!plugins$ % !plugin$ !groupId$org.codehaus.mo#o!"groupId$ !artifactId$tomcat-maven-plugin!"artifactId$ !configuration$ !url$http:""(A).(,+.()A.*,:+;+;"manager"html!"url$ !"configuration$ !"plugin$
!plugin$ !groupId$org.codehaus.cargo!"groupId$ !artifactId$cargo-maven)-plugin!"artifactId$ !"plugin$ % !"plugins$ % !repositories$ !repository$ !id$codehaus!"id$ !name$6odehaus maven repository!"name$ !url$http:""dist.codehaus.org"!"url$ !layout$legacy!"layout$ !"repository$ % !"repositories$
#ote that automatic deployment%undeployment only wor!s without further configuration in !"V#$%&H'!#(conf(settin)s.xml if the managers username is admin with empty password