Java Reference
In-Depth Information
the directory structure: declare the source directories, the build directories, and many
other directories needed for the build itself. And although the Ant community tries to
imply some directory names and directory structure, there's still no official specifica-
tion (convention) of how a directory should be named. For instance, many people
declare the target.dir property to denote the directory that holds their compiled
classes, whereas others may be accustomed to using the build.dir property and it
seems unnatural to them to use target.dir . Also, many people place their source
code in the src/ directory, but others put it in the src/java/ directory. The Maven team
decided that instead of allowing the software engineers to choose the build structure
every time themselves, they'd introduce a convention for this. This resulted in what's
now called the “Maven convention of directory structure.” With Maven, instead of
defining all the directories you need, they're defined for you. For example, the src/
main/java/ directory is the Maven convention for where the Java code for the project
resides, src/main/test/ is where the unit tests for the project reside, target is the build
directory, and so on. And it isn't just the directory structure. Later on when we discuss
the plug-ins themselves, you'll see how every plug-in has a default state already
defined, so you don't need to define it again.
That sounds great, but aren't we losing some of the flexibility of the project? What
if we want to use Maven, and our source code resides in another directory? Maven is
great at this. It provides the convention, but you still can, at any point, override the
convention and use the configuration of your choice.
10.1.2
Strong dependency management
This is the second key point that Maven introduced. At the time the project was
started, the de facto build system for Java projects was Ant. With Ant you have to dis-
tribute the dependencies of your project with the project itself. Maven introduced
the notion of a central repository —a location on the internet where all kinds of arti-
facts (dependencies) are stored. The Maven build tool resolves them by reading your
project's build descriptor, downloading the necessary versions of the artifacts, and
then including them in the classpath of your application. This way you only need to
list your dependencies in the dependencies section of your build descriptor, as
shown here:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>jmock</groupId>
<artifactId>jmock</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
 
 
 
 
 
Search WWH ::




Custom Search