views:

146

answers:

6

I am trying to figure out the use of Maven and I got many articles describing its features and uses. But I am just not able to understand the actual use of Maven from productivity standpoint.

I am fresh out of school and working as an intern and these guys want me to use Maven for my project. So, from what I am used to in our school projects was just create a new Java project in Eclipse, write your Code, create a .war (if web-based) and paste the code to the webapps folder of Tomcat and start the server!

So,

  1. Where does Maven come into picture? I have used Ant and I understand Ants benefit of a standardized build process. But why do we need an advanced Ant in form of Maven?

  2. In any case, I need to use it, so where do I get started - basic flow, some good tutorials?

Thanks

+4  A: 

Maven is used to manage the build, testing, and deployment processes. It can separate the unit tests and integration tests so you only run them when necessary and cut down on build time.

It is also a dependency manager, which means when you realize the server piece of your project needs apache commons-logging 1.0.4 but the client conflicts with anything past 0.7.9, you can just add a couple lines to the respective pom.xml files, and Maven handles all of that (downloading, installing, and keeping track of the different versions of those dependencies).

I was not a believer before my current task, but after 2 years using it for large enterprise applications, I definitely respect what Maven brings to the table. There are a lot of online resources but if you are going to be the lead on this and really feel uncomfortable, I recommend getting a book -- the O'Reilly one is helpful.


Forgot to mention that there is an Eclipse plugin which makes it almost painless to use with Eclipse: m2Eclipse.


Second update for example pom.xml segment to answer OP question:

Your pom.xml will contain XML code such as:

<dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.0.4</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

These are downloaded from the central Maven repository (google "maven nexus") or you can configure your own additional repositories (like for your own projects, or if you are not Internet-connected).

Andy
So, maven will download and install the required jar files named in the dependency? How?
zengr
+1 for m2eclipse
stacker
@zengr, it downloads them to a local "repository" (think cache) and includes JARs from the repo on the classpath when running tests, compiling, etc. When packaging up a .war for example, the JARs are then packaged into the .war.
matt b
Got it, thanks :)
zengr
+2  A: 

Free books about Maven can be downloaded from Sonatype (where the original developers of Maven come from.

Also see the documentation on the Apache Maven website.

Jesper
+1  A: 

Where does Maven come into picture? I have used Ant and I understand Ants benefit of a standardized build process. But why do we need an advanced Ant in form of Maven?

  • Maven introduced "convention over configuration" this helps if some colleagues write bigger ant scipts than code. plus dependency management, the only trouble is to convert monolithic projects with many artifacts.

In any case, I need to use it, so where do I get started - basic flow, some good tutorials?

helpful.

stacker
+1  A: 

I had exactly the same perception as you and for years I avoided Maven.

The thing is, it allows you to easily get the required jars your application may need( called dependencies - jars and other things - ) . So the next time somebody else run your project he will get the jars automatically.

I know that's a bit hard to grasp, until you work with an existing projects using it.

For instance I downloaded an open source project recently, which depended on 10 or 12 different on different jar versions. After downloading the source code and executing Maven, all those jars ( and a lot more others ) were downloaded for me.

The problem with Maven ( as a friend of mine told me ) is that to perform a "Hello world" program, it first downloads the world to greet him. :P

OscarRyz
thanks for the exp sharing :)
zengr
:) You're welcome. BTW, I tried to get into all that documentation, tutorial and everything, but nothing make more sense as just running it, after that everything start making sense.
OscarRyz
A: 

The latest netbeans also has a pretty good maven integration.

Alfred
A: 

If you are within an organization, try to build a maven repository proxy. Artifactory is a good option.

Jason