Originally posted by Tushar Madhukar:
Hi,
I am new to the Maven tool. I have a few queries:
1. If my project depends upon a jar, do I necessarily need to put it
in the local repository and then declare it in the dependency tag in POM? Can't I keep it outside and still let the build process access it?
2. While using the WAR plug-in for creating an app war, does Maven mandate that I keep all web components (HTML, JSPs, web.xml) in a specific directory? Is it possible to keep them as one wants and specify the locations in the POM, so that the plugin knows from where to pick what component?
I have been working with ANT all this while and hence I am a bit uneasy with the fact that Maven imposes a structure on my project organisation.
Regards
Hi Tushar,
It makes many people uneasy how Maven appears to impose structure on a project. Maven follows the rule of convention over configuration. What that means is that instead of telling (or programming) the tool where to find everything you follow a convention that allows the build to assume certain things. That works perfect for green field projects but has some trouble when porting an existing project. In most of these cases Maven can be configured to look elsewhere for build artifacts. There are guides on how to migrate an existing Ant build on the site as well as some good info in the new Maven book
here. So I won't address that issue as I am no expert, instead I referr you to those resources. I will suggest, however, that you follow Maven's standard layout for new projects because it makes more sense than you think and it won't hurt at all (I promise). As far as locating dependencies, there is a systemPath attribute on the dependency tag that will allow you to specify where in the file system a dependency exists. It is NOT a good habit to use that attribute because it violates the principles of Maven and works against one of the many benefits of the tool. If you are using that attribute then you are managing your dependencies manually and creating MORE work for yourself.
Maven actually removes the burden of dependency management as well as many other burdens from you if you just stop fighting it. That's where most of your discomfort lies when beginning with it. With Maven you no longer have to manage your project structure, your build lifecycle, or your dependant artifacts. These are all mundane details that add no value to your project. (Who really cares if your source is under src/java or src/main/java? Who cares where the DOM4J jar file was referenced from as long as it is found right?) Like I said before with new projects it makes perfect sense to let Maven handle all of it for you. To see the real value in all of this start a brand new simple web project using both Maven and Ant and see how much work goes into both builds. One command in Maven will spit out the template project and pom file allowing you to just start coding whereas you can spend a day recoding the same build system you've coded somewhere else, and getting it just right. (You could easily spend a few minutes in Ant but your build file would not be complete, nor would it be extensible.)
To really appreciate Maven you have to look at things entirely different and be able to say that you DONT want to recode your build. You don't want to program your build at all. You DONT want to manage your dependencies. And you DONT want to declare your project structure. Instead you want to follow a common structure that just gets the job done and start programming you logic.