May 18, 2012

Maven cheat sheet for the beginners

Maven is a build automation tool used by the java developers. Some of the commands which I use on daily basis are:

Create a Java Project
mvn archetype:create -DgroupId=com.devfaqs.project -DartifactId=MyProject
Above is a single line command to create hello world java project. The command creates the project in a well defined directory structure along with the provision to write and execute junit test cases for the project created

Compile a Project
mvn compile
The compiled classes are stored in target/classes directory

Package a Project
mvn package
The project is packaged in either of the following formats: jar, war, ear

Run Tests
mvn test
Run unit tests using a suitable testing framework

Clean a Project
mvn clean
The target directory is removed from the project

Install the Project to local repository
mvn install
This will install the project package in the local maven repository which usually resides at %USERPROFILE%/.m2 or $HOME/.m2 directory

Eclipse Integration
mvn eclipse:eclipse
The maven project can be imported to eclipse after executing the above command

Generating Ant build files from Maven
mvn ant:ant
This will generate build.xml, maven-build.xml, The same project can be imported into eclipse using ant build file

No comments :

Post a Comment