Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

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

Using Maven2 - For Beginners

Posted by U.S. Wickramasighe | Posted in , , , , , , , | Posted on Sunday, December 07, 2008

Maven2 is completely new source code building System. Unlike previous types of builders (ie:- Ant, Make) Maven2 is not task oriented..In Abstract sense , for Maven2 you have 2 specify 'what' not 'where' / 'how to' in building your source code.

Pom.xml is the descriptor file for Maven2 where you can specify ,

  • code dependecies
  • Bundle information (Version, Artifact Id ,Group Id..)
  • OSGi related stuff
  • plugin information (compiling,OSgi,Ant,etc )
Maven2 has a local central repository (ie:- in Linux this is ~/.m2 directory) and also you can specify remote repositories as well incase to download the dependent code if not available in local one.

'Pom.xml' descriptors canbe grouped hierachically when necessary to make your build more efficient and reliable . This is done by specifiying a parent for each child 'Pom' and specifying child 'Pom' modules in the parent as well.In this scenario Packaging type specifier for parent will always be 'Pom' while children will have necessary packaging types (ie:- bundle,jar ; Packaging type --> is how you define the output of the build )

Maven2 recognizes each module/source build as an Artifact. Hence you need to specify Group Id, Artifact Id for each build.

  • Group Id - which group does the build belong to .
  • Artifact Id - Specific name/Identifier of the build
So hence when you explore ~/.m2 repo , your build will be located (if you have already built it of course..) at ~/.m2/ ${GroupId}.replaceAll(".","/") /${ArtifactId}/${Version}

I will discuss maven2 commands in the next Article...So stay tuned...

------------------------------------------------------------------------------
My next post Using maven2 part2