Following our target, create a XP Software Development Environment, today we add another tol for the box.
Maven is a project management tool with the following main features:
- Convention over configuration: it provides many estructural standards for the project in order to make easy the development, and avoid problems with many configuration files:
- ${basedir}/src/main/java: your code
- ${basedir}/src/main/resources: configuration resources
- ${basedir}/src/main/webapp: web, css, html, jsp … files
- ${basedir}/src/test: test classes
- ${basedir}/target/classes: compiled classes
- ${basedir}/target: jar, war, ear…. for packages
- ….
- Manage all life cycle steps for the project:
- Very simple Life Cycle: Compiling –> Test –> Packaging
- In every life cycle steps you can execute goals. In packaging for example: mvn jar:jar
- Manage the dependencies with other projects, this is the feature that takes my attention:
- Forget download jar libraries for spring, hibernate, configure them in Java Buil Path,….. bad stuff. Solution: write your dependencies in pom.xml, and it download them and makes the Build path.
- The Archetypeeeees ¡¡¡¡ They are application skeletons with preconfigured pom.xml to develop projects like grails, seam, roo,… Take a look at Appfuse and this archetypes when you will create a project with maven in eclipse.
- Have a plugin ecosystem to execute goals for all the phases in every kind of project.
Furthermore in my case gives some fundamental features:
- Full Elcipse integration (M2Eclipse).
- Good documentation: Maven the Definitive Guide and m2eclipse Documentation.
- It integrates our projects easy with other XP tools like Continuous Integration, TDD, code analizers,…
Install with the following instructions:
- Download Maven in a folder in your system: c:\dev\frameworks\maven2
- define this folder in PATH as M2_HOME. You can test it: mvn -v
- Eclipse installation Help > Install New Software > Add http://m2eclipse.sonatype.org/update/
For the begining we are going to make an example with Eclipse. Create a new project File > New > Other … > Maven > Maven Project. Mark “Create a simple project” to avoid archetypes now. Maven makes you fill Group Id, Artifact ID.
Create the following example Class:
package com.lebrijo.ejemploMaven;public class Hello {public static void main( String[] args ) { System.out.println( "Hello World!" ); } } |
The command “mvn install” generate the jar that we execute with “java -cp target/simple-1.0-SNAPSHOT.jar com.lebrijo.ejemploMaven.Hello”. But in Eclipse you can execute as Java Application.
To add a dependency, right button over the project > Maven > Add dependencies:
We could use the Spring dependency injection making the search, and select the concrete version. After thar we update the libraries with right clic over the project > Maven > Update Dependencies.
This actiion generates the followin pom.xml file:
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>3.0.0.RELEASE</version> </dependency> |
Take the example project from the following link: Maven2 basic example.
Oh hon. My heart. She will be aewosme. She is aewosme..because she has you. Just wait until she is 9 and you are like so not even close to being cool anymore and she hangs at the house down the block all day. HA! Then it’s fun to just embarrass them in front of their friends. Which is VERY cool. xo