What is Maven for?

Asked

Viewed 24,414 times

16

I often find large projects that have the pom.xml file, but I never understood the usefulness of it, I just found out it’s something related to Maven. Finally:

  • What is Maven for?
  • What is the pom.xml file for?
  • 2

    I’d forgotten that article: Installing, configuring and using Maven to manage your dependencies and your Java projects, it is super complete and makes my reply more like a small introduction of the subject :)

  • Wow, really cool. I’ll read it now, thanks (:

  • 1

    Nicolas, I am part of the Demoiselle community which is a project of a framework in Brazilian free software. Our community offers, through SERPRO which is founder, a course in distance learning format in what we call track-Demoiselle that covers, in addition to the course of the framework itself, the prerequisites for using Demoiselle. One of the courses is about apache-Maven: https://moodle.ead.serpro.gov.br/blocks/course_catalog/guia_aluno.php?exibe=c&org=2&categoria=2355&url If you are interested in contacting us.

1 answer

25


Maven is a tool developed by Apache, it serves to manage dependencies and automate your builds.

Already the pom.xml is the Maven configuration file.

Managing the dependencies

It is very common to find projects that make use of other libraries or frameworks, to use them you need to access them through the dependencies. Java dependencies are compressed files and stored with the extension .jar. Some of these dependencies have one or more sub-dependencies and some of them have one or more sub-dependencies, and so on. Instead of when you need a dependency you go in search of it on Google, download it, add to your project and find that it needs X new subdepences and stay in a giant cycle hunting for dependencies, you can automate this process boring and tiresome, and focus on development which is what really gives your project value.

Maven automates this for you!

There is a repository that is considered the central Maven that can be accessed through this link: https://search.maven.org . In addition to it there are many other repositories scattered around, and a good way to find them is through the site http://mvnrepository.com/ that indexes other repositories and provides a friendlier way to search for the dependencies you need.

When searching for a dependency to be accessed through Maven you will get an XML snippet that serves to configure the pom.xml of your project and indicate that you will be making use of this dependency in your project. By adding this snippet, Maven downloads it and stores it in a local repository on your computer, if you own more than one project using the same dependency you will only have a single file on your computer, in your local repository organized by Maven.

Another great advantage of the dependency being in a local repository, not in your project folder, is that when using versioning tools such as GIT you don’t need to add your own .jars in it, since the responsibility to manage dependencies is no longer yours, but Maven’s.

An example XML snippet that configures Maven to use a dependency:

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.3</version>
</dependency>

Automating the builds

You can automate your project tasks that can be file generation .jarexecutable s making appropriate use of the dependencies or even the deploy of applications web.

For example: Build generation in the Maven project and Creating JAR with Maven dependencies

  • That one http://mvnrepository.com/ never been a central repository, it only consults in some repositories, if you notice that the available download is a link to the external ones. To the center, look http://central.maven.org

  • @brunocesar ops, I’m going to fix this part so I’m going to do a little research to see how this works, and maybe mention that other tb repositories can be added in pom. Thank you

  • Good answer, Math! Just note that @Bruno is right. mvnrepository.com is a repository indexer, a user-friendly way to locate dependencies. Particularly, I find it faster and friendlier than seeing it directly in the repository.

  • @utluiz good answer is yours on your blog, after I remembered her (reading your answer on deploy) gave me the urge to delete mine, rs.. But somehow I think that all that text wouldn’t even fit here, so there’s my brief. And I’m going to fix what you observed. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.