• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why Use Maven?

 
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

Maven's website has plenty of documentation explaining what it is but I'm a little unclear about why it's used. In the most basic possible terms, why do businesses use Maven as a build tool? From my admittedly limited experience with it, its main capability seems to be a way of making sure that key JAR files (dependencies) are on your project's build path. Is there much more to it than that?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Simon, welcome to the Ranch!

Well that in itself is a pretty darned big deal. Managing your own dependencies manually becomes a pain in the butt very quickly. So there's that.

Otherwise, it's a pretty good build tool which takes the pain out of compiling, organising, and packaging your application. Again, to do this manually would get old real quick. Aside from the fact that you'd mess it up a lot because it's so tedious.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim. :-)

One caveat I should have included in my OP is that while I'm well acquainted with Java I've never worked as an out-and-out Java developer on a development team before, hence things like Maven are relatively new concepts to me. Back when I started learning Java, about 15 years ago, there wasn't anything similar to it that I worked with.

I'd read previously that it's unusual for a development team to change their project's POM.xml file after the project's been started. Is that accurate? It doesn't seem so to me as if you suddenly find out you need a new series of JARs you'll have no choice but to include them in your Maven repository.
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:I'd read previously that it's unusual for a development team to change their project's POM.xml file after the project's been started. Is that accurate?


Not really no. We update our pom.xml files with relative regularity. Perhaps we want a new version of some dependency, a new version of Java, a completely new dependency altogether, or want to change some part of the build process. There are many many reasons and will vary from project to project and team to team.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find detailed discussions by searching this forum's history. But in brief:

1. Maven projects are self-contained. I can send you a Maven project and no matter where in the world you are and (to a certain extent) no matter what OS you are running, you will be able to successfully produce the maven output product with no more local configuration than an installed copy of Maven, an installed copy of Java and the MAVEN_HOME and JAVA_HOME environment variables. I've been in shops where I couldn't do a successful/clean build of a project the person on the next desk over when IDE-based builds were the norm.

2. Maven projects are consistent. Love it or loathe it, you know where the parts of a Maven webapp project will be found. So the learning curve is a lot less when someone hands you a Maven project.

3. Maven projects are reliable. Because you request dependencies with absolute version numbers, the chances of "gotchas" from working with the wrong version of a library are virtually eliminated

4. Maven projects are self-assembling. Dependencies are automatically fetched as needed. And automatically cached so you don't have to re-fetch them on every build.

And finally, Maven projects are shareable. You can set up a proxy server such as Sonatype Nexus and it will not only cache fetches from the Internet-based Maven repos, it acts as a local shared repository for your internal developers.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aside from the great reasons already mentioned, I also really like that the POM describes what your project is. You can list a project name, product name, project developers and collaborators, a website, description, etc.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:1. Maven projects are self-contained. I can send you a Maven project and no matter where in the world you are and (to a certain extent) no matter what OS you are running, you will be able to successfully produce the maven output product with no more local configuration than an installed copy of Maven, an installed copy of Java and the MAVEN_HOME and JAVA_HOME environment variables.



Wouldn't I also need the source code of whatever project you happen to be working on? I don't see how Maven supplies that. I see how it manages dependencies (downloads them from repositories either internal or internet).
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maven does not supply the source code. It is the programmer who has to supply the source code
and then maven takes the source, downloads the dependencies mentioned in POM and builds a WAR/JAR/EAR or whatever the target is.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:

Tim Holloway wrote:1. Maven projects are self-contained. I can send you a Maven project and no matter where in the world you are and (to a certain extent) no matter what OS you are running, you will be able to successfully produce the maven output product with no more local configuration than an installed copy of Maven, an installed copy of Java and the MAVEN_HOME and JAVA_HOME environment variables.



Wouldn't I also need the source code of whatever project you happen to be working on? I don't see how Maven supplies that. I see how it manages dependencies (downloads them from repositories either internal or internet).



When Tim mentioned "Maven project", he also implied the source code. A Maven project isn't just the POM, but also the rest of the sources and resources.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone. I realise that these are quite banal or dumb questions but I appreciate the time taken to answer them nevertheless.

One final question on this - can Maven be used to do things like set up a directory structure on a local machine and download files from remote locations that aren't JARs?
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No question is dumb.
I have never used maven for these kind of task, so cannot comment.
We have created directory structures and also downloaded files from remote locations in our projects, but using Java.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:
One final question on this - can Maven be used to do things like set up a directory structure on a local machine and download files from remote locations that aren't JARs?



Why do you want to do that?
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A third party application that my team works with. It has several instances and it's convenient to create different directories for each instance under the same root directory. We've a shared network location where the application files are stored and I'd like to be able to use something that newcomers to the team can simply click on that will then create the appropriate structure on their local machine and copy the relevant files. I could write something to do this, sure, but if there's something similar out there already I'd prefer to use it first.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:

Simon Ritchie wrote:
One final question on this - can Maven be used to do things like set up a directory structure on a local machine and download files from remote locations that aren't JARs?



Why do you want to do that?





Good evening all ,
This is sreenivas ,

1) Maven will resolve (framework like spring 3.2 .....)version compatibility problems because it will maintain central repository.
2) previously Tim discussed Maven is reliable, consistent ,flexibility and easy to learn and use
3) dependencies automatically updates in the local repository from central / maven repository
4) we have facility to add custom jars into maven repository
5) easy to use maven like we can create maven projects through command prompt / IDE's eclipse , netbeans ....etc
6) easy to build our reliable target war / ear / jar ..etc

finally Main benefit from Maven is its life-cycle it is very flexible.

any updates please suggest me ... thanks in advance.

SreenivasM.



 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:A third party application that my team works with. It has several instances and it's convenient to create different directories for each instance under the same root directory. We've a shared network location where the application files are stored and I'd like to be able to use something that newcomers to the team can simply click on that will then create the appropriate structure on their local machine and copy the relevant files. I could write something to do this, sure, but if there's something similar out there already I'd prefer to use it first.



Maven is a build tool. It's easy to start thinking of Maven as do-everything-that-developers-need-done tool, but it's a wrong thing to do. I know because I've fallen in the trap before. You are not going to ask Maven to get your coffee for you too, right?

The job of Maven is to automate and integrate activities required to build, test and package the application. Maven is not an installation tool. Using Maven as an installation tool will be like thwacking your head with a fish. It will hurt and you will realize that if you have to hit your head properly, maybe you should have used a hammer

What I would do is simply write a script that installs your third party software in the right folders. It's a one time activity. It doesn't need to be mavenized, and it's much simpler to write a simple script. Or you might want to do something like use vagrant to create a VM that hosts your third party app. You build an image for this VM that has your standardized installation of the third party app. Maven can integrate with vagrant, and bring up the VM as required. So, if you want to run some integration tests that require the 3rd party app, you can setup Maven to bring up the VM, run the integration tests, shut down the VM
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jayesh.

You are not going to ask Maven to get your coffee for you too, right?



Well, if it could... ;-)
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make Maven do just about anything you want. All you need to to find (or create) a mojo to plug into it.

Whether you should or not is quite another story.

A common case is that a lot of people use Maven to deploy webapps. Personally, I stop once the deployable is produced, however. For the wider process of pulling down source and deploying the end result (excepting where I deploy a product to a Maven repository), I prefer to let a CI system such as Jenkins handle those steps.

For stuff like test data files, if they're small enough, I put them in the project's src/test/resources directory subtree. If they're intolerably big or volatile, I'd generally have them external to the project on a fileserver or something like that. That would, of course, violate the concept of being strictly self-contained, but hopefully I wouldn't be doing that for critical build resources and I'd certainly be trying to make sure that the external wackiness was kept as manageable as possible.
reply
    Bookmark Topic Watch Topic
  • New Topic