r/javahelp • u/Lvl20Rogue • 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
6
u/ColetBrunel Dec 29 '19
Let's say you want to create PDF files, to export bills made out of some text organized in a page. Java out of the box doesn't provide anything to create PDF files.
However, if someone knows how PDF files are made, they can program it by themselves, putting the right bytes in a read/write RandomAccessFile so that it is a PDF file. That can totally be done in Java if you know how to.
But not everyone knows how to make the right bytes for a PDF file, and even if they knew, they have better things to do. So instead, there is someone, somewhere, who programmed a simpler way to make PDF files, and can be re-used. Then they published it, in the form of a jar file that contains all the necessary classes. This jar file can be imported in whatever project needs it. This is called a dependency.
The problem of dependencies becomes harder when you start to realize that dependencies have their own dependencies and gathering the whole thing becomes tiresome after a while. That's why a dependency manager that has a public dependency repository does all the work for you as long as you can simply name the dependency you yourself are interested in, becomes a huge help.
(Well, in reality, there is more than one guy who made PDF enabling libraries. There are a few different ones around. But not everyone re-does PDF writing/reading just because they need it)
Also, it works particularly well in Java's ecosystem which is full of opensource/free-to-distribute libraries that anyone can put in any public repository they want as that is explicitly allowed. Because of that, even if you do need dependencies that aren't freely redistributable, the mere fact that you're using Java and the norm here is to use a Maven repository, will make your library provider willing to help you out by providing realistically easy solutions to manage their library using Maven.