However, I was trying a few new projects and all the samples I tried were mostly in Maven. It had been my New Years Resolution for many years to learn Maven. But, they remained just that , New Years Resolutions and never got a chance to actually either learn or use it in any of my projects.
Last week, I had a few hours of free time, and decided to actually try Maven from scratch. I was always intimidated by the POM; which is THE PROJECT OBJECT MODEL. No idea why. I tried a few simple commands and was able to clearly understand and learn Maven the right way.
If given an option now, what will I choose for my new project, can you guess? Nope, you thought I would choose Maven, you are wrong. I would still use Ant. However, if I am writing an article, or giving a presentation, I would rather use Maven. It is so simple to create a new project, where Maven does all the work for you.
- Open a command prompt, and type the following command:
- mvn archetype:create -DgroupId=org.meeras.sample -DartifactId=sample -DpackageName=org.meeras.sample
At this point, Maven created the entire directory structure for me as shown below. How cool is that?
- The POM at this point is very simple, with just JUnit as it's dependency. If you want to see effective POM, which Maven always executes from, run the following command to see all the Parent POM's and also the Super POM.
- mvn help:effective-pom
- Maven creates a simple Java class with a static main which you can run from the command line where the POM.xml file resides .This following command compiles, tests, packages and installs the sample application.
- mvn install .
C:\dev\projects\maven-samples\sample>java -cp target/sample-1.0-SNAPSHOT.jar org
In one step I was able to create an entire project structure. That's the biggest plus for Maven. Convention over Configuration.
So, that's it for today. I will write more about Maven the next time I do something even more interesting.