Defaults that are implicitly followed by Maven can be
overridden in the build section of the pom.xml. In the following example, we
are overriding the target package name. By default, the target package name in
our HelloWorld example will be HelloWorld-1.0-SNAPSHOT.jar.
group Id with your site or organization name. -->
<!-- name of our application -->
<!-- Version of
the XML schema structure used in the project. -->
<!-- Name of our
the target package name. -->
8.0 Maven Dependencies
1.Dependencies are other resources that we want to
use inside of our application.
2.Maven will pull transitive dependencies based on
the dependencies we list.
3.Minimum required info to pull dependencies:
1.Development starts off as a SNAPSHOT
2.SNAPSHOT allows us to push new code to a
repository and have our IDE or command line automatically check for changes
3.If we specify a SNAPSHOT version in our pom.xml,
Maven will pull down new code every time it runs and uses the new code.
4.SNAPSHOT keyword has to be all capital. It does
not work as a SNAPSHOT otherwise.
5.This SNAPSHOT functionality saves you from
re-releasing versions for development.
6.Never deploy to production with a SNAPSHOT because
we cannot reproduce or re-create that code. The next time we compile the code,
the functionality could be different in the code.
7.A release does not have to have a specific
naming convention. Example: HelloWorld-1.0.jar, HelloWorld-1.0.1.jar
8.Milestone releases like HelloWorld-1.0-M1.jar or
HelloWorld-1.0-RC1.jar do not effect Maven. Such milestone or release candidate
versions are published for evaluation purposes and should not be considered as
9.RELEASE versions are sometimes named with a
keyword RELEASE, although it is not necessary.
1.Types refer to the type of resource that we want
to include inside of our application.
2.The default and the most common type is a jar.
3.The current core packaging types are pom, jar,
maven-plugin, ejb, war, ear, rar and par.
4.The type of pom is referred to a dependency pom.
a.All dependencies inside the pom are downloaded
into our application.
b.Commonly referred to as a dependency pom.
c.Example: If you have web services in your
organization and you want to group all of these dependencies that we use for a
anytime we want to create a web service, like Jersey libraries and other
different XML dependencies, all those dependencies can be put into one pom and reference
that pom in your project and Maven will download that into our application.
5.Types refer to packaging inside our application.
If we are building an artifact for other people to consume, we need to specify
our packaging in the pom.
8.0.3 Transitive dependencies
1.The main reason people begin using maven.
2.If we add a dependency like hibernate, it will
go ahead and pull down any and all transitive dependencies that hibernate
3.If there is a conflict, Maven will resolve those
by choosing the newer version.
Six scopes available for dependencies:
b.Resources or artifacts are available everywhere
inside your application.
b.Means the artifact is going to be available throughout
your entire build cycle, but it’s not going to be added to the final artifact.
c.Example: servlet-api, xml-apis
a.Not needed for compilation
b.Needed for execution
c.Included in the runtime and test classpaths, but
not the compile classpaths.
d.Example: Dynamically loaded libraries like jdbc
e.Not bundled with our final artifact
a.Available for the test compilation and execution
b.Not included in the final artifact
a.It is recommended NOT to use system as it is
very brittle and breaks the reason for wanting to use maven.
b.It is used for hard coding a path to a jar on
your file system.
1.Identical to dependency repositories, just deals
2.Maven will only look for plugins in this repo as
by design a plugins repo is usually a separate repository.
3.Defined very similar to dependency repository.
4.Snapshots and releases just like the dependency
5.Optionally, custom plugins can be created and
stored in an internal or corporate repository.
1.Snapshots and releases can come from the same
repo, but usually organizations prefer to keep them separate.
2.Most projects end up having a lot of snapshots,
release candidates and milestone releases for each release. It is easier to
maintain a separate repo for releases to make it easier to push truly
releasable code to an app store or a customer access site.
10.0 Maven Plugins
Maven uses plugins to build and package our application
beyond just downloading and storing artifacts locally.
1.Goals like clean, compile etc. are plugins
configured in the maven install.
2.These goals are defined in the super pom which
are added to your project’s effective pom.
3.Goals are always tied to a phase.
4.The default goal’s phases can be overridden in
your project’s pom if required.
1.validate – this validates that
a.The project is correct
b.It has all the plugins needed
c.It has all the artifacts downloaded
d.All structures are in place
e.Has permissions to create directories.
a.Our source code compilation happens.
b.Testing code does not get compiled.
a.Testing code gets compiled.
b.Testing of the compiled source code happens.
a.Packages all of our code in its defined
packaging such as jar.
b.It doesn’t do anything with it once it is
packaged, but allows us to test to make sure that everything is in the proper order
in which it should be.
c.Usually, developers tie generating sources or
JavaDoc to this phase.
a.Allows us to deploy and run integration tests
b.New to maven 3. Not used by most yet.
a.Runs checks against package to verify integrity before
installing to our local repo or our private repo.
a.Install the package in our local repo
a.Copy final package to a remote or private repo
10.0.3 Compiler plugin
1.The plugin used to compile the source code in
2.Used to compile both source code and test code
using different phases.
3.Invoke java by setting the classpath with the
dependencies from our application.
4.Defaults to java 1.5 regardless of which JDK is
5.The configuration section allows for
customization by overriding the JDK version, memory settings etc.
the target package name. -->
for every plugin as the fields that they support can be different.
context sensitive help in IDE for this section is not available because it can
be a Cdata field in XML. -->
10.0.4 Jar plugin
1.Used to package our compiled code into a jar
2.It is tied to the package phase of our build
3.Configuration section allows for customization:
a.Includes or Excludes – to only package certain
things in your jar.
b.Manifest – builds a manifest for our project.