Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This

...

guide

...

assumes

...

you

...

are

...

using

...

Maven

...

2.0.4

...

or

...

later

...

(

...

http://maven.apache.org

...

)

Getting started

Before we get too far ahead, it is important to know some basics concepts of Maven. The most important thing to understand is that unlike Ant, Maven has no concept of procedural tasks that get run. Instead, Maven has a concept of a build lifecycle in which plugins (somewhat similar to Ant asks) can attach to. When you execute a maven build, you specify a point in the lifecycle that you want the project built up to. The phase compile comes before test, and test comes before package, and package comes before install.

Installing

The install phase simply means that maven should build up the project ("package"), and then install it to your local repository (found in ~/.m2/repository).

...

There

...

is

...

can

...

be

...

used

...

by

...

any

...

other

...

maven

...

project

...

you

...

build.

...

To

...

run

...

a

...

basic

...

install,

...

simply

...

invoke:

{
Code Block
}
> mvn install
{code}

That's

...

it!

...

Maven

...

will

...

download

...

all

...

dependencies

...

it

...

needs,

...

run

...

all

...

unit

...

tests,

...

package

...

up

...

the

...

jars,

...

and

...

then

...

install

...

the

...

jars

...

locally.

...

You

...

can

...

also

...

find

...

the

...

jars

...

in

...

the

...

target

...

directories

...

of

...

each

...

module.

...

For

...

example,

...

action/target/action-2.0-SNAPSHOT.jar

...

would

...

be

...

where

...

the

...

main

...

jar

...

is

...

built.

Warning

Some

{caution}Some

dependencies,

such

as

JavaMail

and

Activation,

can't

be

downloaded

automatically

due

to

license

restrictions.

Fortunately,

Maven

gives

you

a

nice

error

message

showing

you

how

to

install

these

to

your

local

repository.

Simply

download

the

required

jar

from

Sun's

website

and

then

use

the

command

supplied

by

the

error

message

to

install

it.

You

can

then

try

the

build

again.

{caution} h2. Other phases There are other phases that can be useful when working with Maven. The *package* phase will just jar (or war) up the modules. The *test* phase will only run the unit tests. The *compile* phase will only build the source code (but not the test sources). And the *clean* phase will remove all artifacts, typically the entire _target_ directory. h1. Build profiles Now that you know the basics with the Maven build, there is a bit more to learn. M h1. Building IDE project files h1. Tips - mirror - having to run "mvn install" sometimes before the build works

Other phases

There are other phases that can be useful when working with Maven. The package phase will just jar (or war) up the modules. The test phase will only run the unit tests. The compile phase will only build the source code (but not the test sources). And the clean phase will remove all artifacts, typically the entire target directory.

Build profiles

The next step to building Struts with Maven is to understand build profiles. These are simply slightly different configurations for the build. The following profiles are available:

Profile

Description

default

Builds action-api, action, and all sample webapps

xwork

Includes the xwork build

thirdParty

Includes additional modules that cannot be part of the default build due to Apache rules

In the previous example, we didn't specify a profile so the default profile was used. However, most developers will want to use additional profiles as they work on both XWork and other modules, such as the JasperReports integration.

Specify a profile is as simple as:

Code Block

> mvn -Pprofile ...

That is, if you wanted to build all the third-party add-ons not included with the default build, you'd simply do:

Code Block

> mvn -PthirdParty package

Building IDE project files

Tips

  • offline mode
  • skipping tests
  • mirror
  • having to run "mvn install" sometimes before the build works