Maven Commands Reference Mini Guide
In maven , we have several commands to remember and i was thinking of having a page with simple command reference so that i can have a quick look whenever needed. I have compiled a list of mostly used commands and some settings and useful links. Now publishing it so that it could be useful to others too . Feel free to add more commands to the comments section.
1. Compile
mvn compile
2. Compile (offline)
mvn -o compile
will save you a lot of time
3. Install the generated output to the respective repository
mvn install
4. Clean Target Directory
mvn clean
5. Package as jar or war
mvn package
6. Generate Eclipse project descriptors
mvn eclipse:eclipse
7. Run unit tests
mvn test
8. Run unit tests and print the output to console rather than to file
mvn -Dsurefire.useFile=false test
9. Run individual test
mvn test –Dtest=org.shankh.mavenTest
10. Package without running tests
mvn package -Dmaven.test.skip
11. Install without Running Tests
mvn install -Dmaven.test.skip
12. To download source code into your maven repo:
mvn eclipse:clean eclipse:eclipse –DdownloadSources=true
13. Create a new project
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app
Comment : Instead of ‘generate’ i wrote ‘create’ initially, but as simonz correctly pointed out, mvn archetype:create is now deprecated. so use mvn archetype:generate instead.
14. Create a Web Application
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-webapp
-DgroupId=com.mycompany
-DartifactId=my-app
15. Start embedded Jetty
mvn jetty:run
16. Deploys a WAR to embedded instance of Jetty and starts it
mvn jetty:run-war
17. Specify Java Build version
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
18. Generate site for a single project
mvn site
19. Generate Javadoc
mvn javadoc:javadoc
20. Set Maven_opts System environment variable (will save you from out of memory error)
MAVEN_OPTS=”-Xmx512m -Xms256m -XX:MaxPermSize=128m”
21. Setting M2 variable in eclipse (informing of repository location
Goto Window -> Preferences -> Java -> build path -> classpath variable -> New Name: M2_REPO Path: C:\Users\my_user_name\.m2\repository (In vista) C:\Documents And Settings\my_user_name\.m2\repository (In XP) ~/.m2/repository (in Linus/ unix flavours)
22. Links
1. Settings.xml sample: http://maven.apache.org/maven-settings/settings.html
2. Maven Download: http://maven.apache.org/download.html
3. M2 eclipse download: http://m2eclipse.codehaus.org
4. M2 eclipse update site: http://m2eclipse.sonatype.org/update
5. Cargo: http://cargo.codehaus.org/
6. Jetty: http://jetty.mortbay.com/jetty/

July 14th, 2009 at 6:08 am
I just knew of mvn exec:java -Dexec.mainClass=”com.example.Main” [-Dexec.args="argument1"] …
mvn help:effective-pom
mvn dependency:tree
July 14th, 2009 at 6:46 am
Defines and other options typically are listed at the end so
mvn -Dmaven.test.skip package
is usually written as
mvn package -Dmaven.test.skip=true
July 14th, 2009 at 11:37 am
Is there a way in maven to get all the life cycle phases (aka tasks) that the project can execute – equivalent of that is ant -projecthelp.
July 14th, 2009 at 3:00 pm
Thanks for compiling this, pretty useful!
July 14th, 2009 at 7:28 pm
mvn archetype:create is deprecated
use “mvn archetype:generate” instead of it
it’s a goal to create project interactively
August 4th, 2009 at 2:16 pm
[...] Continue reading here: Maven Commands Reference Mini Guide | Shankh.com [...]
November 18th, 2009 at 3:46 am
Option to download javadoc as well
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Dwtpversion=1.0
December 21st, 2009 at 8:59 am
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Dwtpversion=1.0
above mentioned option only works with eclipse plugin, following is an alternate way
mvn dependency:sources
June 12th, 2011 at 6:13 am
Thx, pretty useful
December 2nd, 2011 at 11:28 pm
good one. quick reference at one short place. Thanks