How to get into maven for the first time

Well, I use maven to organize and automatically download project dependencies, basically open source libraries.

With maven you can get a dependency graph like this one(actually generated by eclipse maven plugin):

where your project is the top one.
The best way to grasp easily what maven is, from my point of view is:

To read:

http://maven.apache.org/what-is-maven.html

Download maven:

http://maven.apache.org/download.html

Uncompress it somewhere in the hard disk, create the enviroment variable home M2_HOME to the uncompressed folder.
It is okay to place M2_HOME/bin in the path to use the maven executable (mvn.bat or mvn.sh)

Then integrate it with eclipse or netbeans to actually see how the IDE’s download automatically all project dependencies:

For eclipse galileo, for example:

Install the maven eclipse plugin, from here:

http://m2eclipse.sonatype.org/

(there is an update site for eclipse)

Then add this:

-vm
/usr/java/your_jdk_folder/bin/java

to eclipse.ini for some reason I don’t understand

THen go to: Window > Preferences > Maven > Installations in eclipse and add your recently donwloaded and uncompressed maven installation, select it.

Then you can File > Import > Maven Project and point it to this sample project (with some example dependencies):

http://www.2shared.com/file/9360954/c26ff629/admision.html (download and extract)

Then, you’ll see how eclipse(maven in the background) automatically download the project dependencies under the “Maven dependencies” category that you can check directly in the pom.xml (the file that actually defines a maven project).

For a general view about the maven repositories, this is how a maven repository looks:

http://hl7api.sourceforge.net/m2/

And you can check your own maven local repository at> $home/.m2/repository, in windows c:/Documents and Settings/User/.m2/repository.

Well, I have just a few months with maven, and I’m realizing it is more than a management/build manager, it is fully extensible with your own plugins, allowing you to do almost anything with/from your project sources.

Furthermore, migrating an eclipse/netbeans/etc native project to maven is not too hard, it is usually no more than create a pom.xml file, place there your own project dependencies and move your sources to /maven_project/src/main/java, the resources (log4j.properties, etc) to /maven_project/src/main/resources and unit tests to /maven_project/src/test/java.

One thought on “How to get into maven for the first time”

Leave a Reply

Your email address will not be published. Required fields are marked *