Why we need maven if there's javac that compiles the code?

221 views Asked by At

I'm totally new to java programming but I'm been programming with .Net and PHP. In .Net all you have to do is run it and it will output exe file in the bin dir which is already deployable, right? I'm confused with the use of maven and javac. I've been searching around but I don't still able to fathom them.

What I'm thinking is that when a certain source code is to be compiled in java, you use the cmd "javac " which is similar to "Run" in .Net. So why do we need Maven?

2

There are 2 answers

6
Rui Filipe Pedro On BEST ANSWER

Maven is a software project management and comprehension tool and not a programming language compiler like javac.

Maven gives you a way to manage your project dependencies through out the development and deployment phases of it, meaning that it ensures that you have the necessary libraries to develop, build and deploy your project. Javac only gives a way to compile your Java code.

0
Nathan Hughes On

Building an application is a lot harder than running javac. There are two big motivations for build tools like Maven: cross-platform builds and dependency tracking.

Part of life for Java developers is needing to build applications on multiple platforms. A build has to run locally on a developer's machine, it also has to run on a Continuous Integration server or on some other environment. (And for some projects developers may have different platforms so even just getting a build to run on everyone's machine may require cross-platform builds.) Getting shell scripts to run in multiple environments proved to be prohibitively painful, and people started creating things like Ant and later Maven.

Any sizeable Java application is put together using dozens of third party libraries and frameworks. Most of these third party components have dependencies on other libraries, keeping track of the tangled mess is too much work for anybody. An important function of Maven is to pull in dependencies, making sure the libraries have compatible versions.