Maven Commands List - Maven Tutorial

Maven Command-Line Cheatsheet

Creating a Project

Create Java Project
mvn archetype:generate -DgroupId=com.example -DartifactId=foobar -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Create web project:

mvn archetype:generate -DgroupId=com.example -DartifactId=foobar -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Basic project tasks

clean project: will delete target directory:

$ mvn clean

validate project: validate the project is correct and all necessary information is available:

$ mvn validate

compile project: compile source code, classes stored in target/classes:

$ mvn compile

test project: run tests using a suitable unit testing framework:

$ mvn test

package project: take the compiled code and package it in its distributable format, such as a JAR / WAR:

$ mvn package

verify project: run any checks to verify the package is valid and meets quality criteria:

$ mvn verify

install project: install the package into the local repository, for use as a dependency in other projects locally:

$ mvn install

deploy project: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects:

$ mvn deploy

deploy-file: can be used for deploying a external jar file to repository:

$ mvn deploy:deploy-file -Dfile=/path/to/jar/file -DrepositoryId=repos-server -Durl= -DgroupId=javax -DartifactId=mail -Dpackaging=jar-Dversion=1.0.1

Eclipse integration

create metainformation: meta files for eclipse are created, can be used for project import

mvn eclipse:eclipse

create metainformation with wtp: same like create metainformation + WTP plugin infos

mvn -Dwtpversion=1.5 eclipse:eclipse

tell eclipse where local repository is located

mvn -Declipse.workspace=/path/to/workspace eclipse:add-maven-repo

run maven tasks in maven (maven eclipse plugin must be installed)

 add maven as external tool – in the dialog there should be a category called 'm2 build' – create new and enter informations – you need to specify every goal seperate. Tasks

Release project

prepare release: informations about versions number are collected

mvn release:prepare

clean release: rollback to snapshot versions

mvn release:clean

perform release: deploy project to remote repository and make tag in version control system.username and password for version control system are taken from server informations in ~/.m2/settings.xml. serverID is same like defined in deploymentServer … this behaviour is not whished

mvn release:perform

perform release with username and password for authentication on version control system

mvn release:perform -Dusername=foo -Dpassword=bar

web project special tasks

create war file, same as mvn package

mvn war:war

Build an exploded web application into ${maven.war.src}. This allows you to mount it in your
application server, and you only need to run it again for dependency and class changes, not JSP
changes. This goal will not clean old dependencies – due to the dangers involved in automating this
for your source tree, you must do that yourself.

mvn war:inplace

delete all artifacts created by war plugin

mvn war:clean

tomcat integration

deploy web project to tomcat

mvn tomcat:deploy

redeploy web project, didn’t work in my test environment

mvn tomcat:redeploy

undeploy web project

mvn tomcat:undeploy

stop context on tomcat

mvn tomcat:stop

start context on tomcat

mvn tomcat:start