Using Maven2 (Contd..)

Posted by U.S. Wickramasighe | Posted in , , , | Posted on Friday, April 03, 2009

Maven2 has very easy to use API for building Source code..I find it very easy to work with Maven2 due to this factor. Basic command for building is 'mvn install' but it's almost always a good idea to build using 'mvn clean install' since it does cleanup of already built code and then starts building fresh..
Before building always make sure your source code resides in '/src/main/java' and resources resides in '/src/main resources' . This is the default behavior for Maven2 and you can always modify it in super 'Pom' (or in you project pom as well ) which is the default root pom for all the pom's for Maven2.

commands

mvn clean install -> compile source and do necessary packaging

mvn compile -> compile and run

options

-Dmaven.test.skip=true -> Sometimes it's better to skip unit tests and test cases , since it will be taking lot of time

-o -> offline building . it's better to use this option if you know necessary plugins and dependencies are residing locally and upto date. Buiding with this option will take much less time since no downloading would occur from remote repositories.

-U -> if maven displays an error of unavailable/error in a plugin use this option. this will force Maven to download the plugin and resume the life cycle


Notes

Please note that if you are building a hudge tree of source code , maven will require a lot of memory to keep it's persistant data. So if the memory limit exceeds Maven2 build proccess will be terminated with out of memory error. So always make sure to set 'Xmx' Memory for Maven to a higher value in these scenarios..

  • open ${Maven_Home}/bin/mvn shell script file... (in Windows mvn.bat)
  • Put set MAVEN_OPTS='-Xmx=1024m' at the start of the script file. Here 1024m can be replaced by any value you desire and only limited by the physical memory of your machine (should be a large value for aforementioned scenario)
For more information on Maven and it's build process go to http://maven.apache.org/
------------------------------------------------------------------------------
My previous post Using maven2 part1

Comment (1)

  1. @ Hey Checkout my Blog ! Its Great - TechFetz

    @

    http://techfetz.blogspot.com/

    www.techfetz.blogspot.com/

    *Online Jobs
    * Android Tricks
    * Windows Tricks
    * Mobile Tricks
    * Free Internet Tricks
    * New Latest Technology