3

I am a very beginner to Java, recently trying to use some existing libraries and suddenly Maven came out in between. I am getting no idea reading the project page on Apache website, what maven is all about.

What is it required for? I am using some a library which asks me to install Maven and some further steps but I have no idea what is it for. Some places I see, it is for automating the process of building, but I can do that easily through NetBeans as well.

Any simple explanations shall be highly appreciated.

EDIT: Thank you all so much!

Please also clarify that if a library that I am using contains a .pom file what does it mean for me. I am building a web-application using some libraries most of which contain .pom files. What does it tell me to do? Does it force me to use Maven?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • As much as I would like to answer this, this is a generic question that really can only be answered by reading. http://maven.apache.org/guides/index.html or even look on StackOverflow http://stackoverflow.com/questions/1414618/good-learning-resources-for-maven-3-mercury – Nix Mar 09 '11 at 13:01
  • 1
    endra Vellisetti In short the POM file contains metadata about the library; version, dependencies, who created it and a lot of other information that describes the library. – snarkyname77 Mar 09 '11 at 14:00

5 Answers5

4

Maven is an opinionated build tool and dependency management system.

  • build tool: it handles the process of turning your .java files into .class files, possibly transforming your resources and packaging everthing in .jar or .war or .ear or .tar.gz or .zip files. In this aspect it's similar to Apache Ant.
  • dependency management: it handles dependencies: it downloads required libraries, makes sure transitive dependencies (i.e. dependencies of dependencies) are downloaded as well, handles conflicting version numbers in dependencies (usually by trying to find a library that fits all requirements). In this aspect it's similar to Apache Ivy.
  • opinionated: it comes with some default configuration that specifies the layout and build process of your project. While it can be customized extensively, this customization can become hard to do. Following the suggested defaults makes using Maven easier, usually.

A key concept in maven is the POM, which contains everything Maven knows about your project. It is found in the pom.xml file. That file is also the best indication that a project uses Maven.

Community
  • 1
  • 1
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • If a library that I am using contains a .pom file, Does it force me to use maven? – Rajat Gupta Mar 09 '11 at 13:29
  • 1
    No, libraries produced using Maven are (usually) simple `.jar` files that you can use just like any other. Using Maven would simply help you manage those dependencies more easily, but if you want to avoid the (not too low) cost of learning and using Maven, then you can ignore that for now. – Joachim Sauer Mar 09 '11 at 13:34
  • @Rajendra Vellisetti, No, though it has been a couple years since I've worked with Java and Maven, just because a library has a POM (Project Object Model if I remember correctly) file doesn't mean you have to use maven. I'm assuming this is still true, Maven can generate a build.xml for you if you wish to use ANT instead. An objective of Maven is that anyone familiar with Maven can walk up to a unknown project that uses Maven and immediately build that project and understand how the source code is laid out. – snarkyname77 Mar 09 '11 at 13:39
2

Maven is similar to Ant: it's a tool that helps you to automate compiling, packaging, and deploying apps.

Since most Java apps have dependencies on 3rd party JARs, it is also similar to Ivy in that it manages getting JAR dependencies from a central place, both your JARs and any JARs they depend on.

Personally, I find Maven to be heavy and hard to understand. I don't like the way it mandates a particular directory layout for my project. Deviating from their standard breaks Maven, as far as I know.

I've always found Ant to be light and easy to understand and run with quickly. I'd recommend trying Ant first and grokking it before tackling Maven. You'll have a working point of reference that will serve you well even if you can't swallow Maven.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • If a library that I am using contains a .pom file, Does it force me to use maven? – Rajat Gupta Mar 09 '11 at 13:33
  • No, it's optional, but if you choose not to use Maven you're on your own. You'll have to get all the 3rd party dependencies, compile and package. – duffymo Mar 09 '11 at 13:37
1

Adding on to @Jigar Jishi's answer:

I have been poking my nose into Maven concept slightly, and from what I understand it's a full set of tools for effective build and packaging management. It utilizes an XML based file (in that sense similar to ANT) to keep track of things.

Maven is a hot subject here and I guess elsewhere on amongst software developers, there are lovers who will suggest Maven to every single related question, and there are haters who will take a shot at Maven at every opportunity. My standpoint is somewhere in between, I find Maven to be unnecessarily complicated and convoluted for my projects, and thus find it not worthwhile to put time and effort into learning.

If it's absolutely critical for your project, then I say give it a shot, but then dont do it half-way. It'll most likely take a lot of time and effort to get things right. But if you manage that you'll probably be happy at the end.. :)

posdef
  • 6,498
  • 11
  • 46
  • 94
  • ohh...okk...so now I understand it is even big thing then I ever imagined.. its requires long learning.! :) – Rajat Gupta Mar 09 '11 at 13:12
  • @Rajendra Vellisetti, I suggest you an IDE which supports Maven such as netbeans, eclipse or intellij. This way the IDE manages the maven file and you can start using it with minimal knowledge as the IDE does almost all of it for you. – Peter Lawrey Mar 09 '11 at 13:16
  • @Rajendra: I'm afraid that seems to be the case, especially if you are, like myself, not used to develop software in a very systematic way. @Peter: While eclipse, and I presume other IDEs, do a decent job handling connections, it's still not very straight-forward/intuitive and things do get complicated. I don't wanna second-guess, or criticize your opinion here, but I really don't see how a beginner can start using Maven just like that without knowing details on builds, packaging, dependencies etc.. – posdef Mar 09 '11 at 13:23
0

Maven is a build tool (a tool that will pack your app into some build like (.jar, .war, .ear) in simple words.

But It is more than just build tool, it supports modularization, transitive-dependencies stuff and many more..

jmj
  • 237,923
  • 42
  • 401
  • 438
0

I would recommend to take a look at the Sonatype WebSite (here).

This company is very implicated in the Maven world ;)

reef
  • 1,813
  • 2
  • 23
  • 36