hello again so far we have just
installed maven now this tool will help
us organize and build our java
application in this video we're gonna
look at how to generate Java projects
using maven will also learn about maven
archetypes and how they help us generate
the code we need for individual projects
to start let's look at the simplest pom
file now this file contains all the
information you need to compile your
application pretty simple right that's
it add this file to a code directory and
you are good to go it sounds almost too
crazy to be true so let's go try it
first create a directory from the
command prompt now you can use any name
I'm going to use test app then create a
text file with this information and name
it palme XML to save yourself from
typing you can also use the palm file
included in the code supplement for this
video once you're done go back to your
command prompt let's type in the command
in VN install you'll see lots of
messages fly by your window now it's
nothing we need to worry about now
basically is compiling all the code
files but in our case we don't have any
and creating a jar file when you go look
in the target directory your code is
compiled and you even have a compiled
jar with no code in it so you're
probably wondering how in the heck does
all this work maven makes many
assumptions about your project and
project structure maven expects all of
your code to be in a directory called
source main Java and all unit tests are
assumed to be under test Java these
directories are relative from the point
where the pom file exists there are ways
to change these directories but it's
easier to just use the defaults the
defaults are based on years of
experience and Java best practices so
your next thought might be well if maven
is assuming where everything is why do I
need to create anything
why do I need to create the palm file
and shouldn't the startup be the same
for all projects well in a way yes
maven uses something called an archetype
an archetype is a maven project template
until kit it allows you to start with a
project that is already set up to use
the best practices there are archetypes
to create jar files we have archives
Enterprise archives portlets Eclipse
plugins and just about every project you
might need to create there's even an
archetype to create a project for
defining new archetypes
so to start let's create a simple hello
world jar in a directory where you keep
your code let's type the following
command now the group ID here is where
you want your project to live in the
repository on your machine you don't
really totally need to understand that
bit right now usually we use the base
package that we plan to use for our
project in this example we're going to
use comm dot your company for now
now the artefact ID here tells us the
name of our project you'll want to use a
single word without spaces here this
will end up being the name of the jar or
or whatever project you create it will
also be the directory where your project
lives for this example we'll use hello
world app so let's run this command and
see what happens
so you'll want to confirm your
selections at the end by typing Y at the
prompt and then we're done your project
should look something like this now open
the pom file in either TextEdit or
notepad or whatever you're using to open
text files on your system you will see
that it's similar to the pom file that
we looked at earlier this pom file also
added something called a dependency a
dependency is a library that your
project depends on the dependency in
this project is for J unit so the
project we just created already has J
unit testing built in and ready to go we
can add similar xml stanzas to add other
dependencies for our project we just
need to specify the correct group ID
artifact ID and version you'll notice
the J unit dependency stanza also
specifies a scope the scope tells me
even when to include the dependency now
at the top of your pom file you'll
notice the group ID and artifact ID we
provided are also in the prom file if we
were to include our project in another
project we'd include these values in the
same way we reference j-unit so it's
great about all this is that we can take
this directory give it to someone else
and if they have maven installed
everything will just compile using the
same commands there's no special setup
needed to run this on another machine so
in this video we've looked at palm files
in archetypes we've also had a quick
look at how dependencies are added to
our maven projects later in the course
when we're ready we'll use a different
archetype for our web service project
for now we'll continue exploring the
basics of maven using this archetype in
the next video we'll look at how we can
specify other Java libraries while we
take a deeper look at the maven pop file