r/javahelp • • Dec 29 '19

Understanding Maven

So i'm recently getting into maven for the first time in my life. I'm a bit confused and i think it's because i don't really know what maven does. I have this POM.XML file in my project. Do i just add a dependency there and maven will magically find the JAR and download it for me, or do i need to somehow also manually download the JAR and the POM just points at it?

Help would be greatly appreciated!

17 Upvotes

20 comments sorted by

View all comments

13

u/joranstark018 Dec 29 '19

Maven will automagically download all dependencies for you.

Maven will download and cache dependencies locally. If you add a new dependency it will first look in the local cache, if not fond there it will search the external repositories, if not found there it will fail the build with an "unresolved" error.

By default Maven will use Maven Central as remote repository you can change this if you have some corperate repository or if you want to include a repository from some third part, it's a list of url:s).

2

u/96dpi Dec 29 '19

But what is a dependency? I tried googling, but it seems like a broad term and does not refer to any specific thing. Can you provide an easy example to understand for someone who has yet to take a data structures course?

1

u/phoulgaux Dec 29 '19

Dependency is basically anything your code uses that is not within your code. In the context of Maven it means any external library (for example a JAR file) you want to be available for your program.