Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Info

Maven 23.0.4 0 or later is required to build Struts 2

First, let's review some Maven basics. Maven uses the notion of a build lifecycle life-cycle to which plugins can attach. ( Plugins are similar to Ant tasks. ) When a Maven build is invoked, we specify a point in the lifecycle life-cycle up to which the build should proceed. The compile phase compile comes before test, and test comes before package, and package comes before install. Once we have Maven setup, we can invoke the Struts build, and specify which phase the build should use.

...

The install phase builds up the project ("package"), and installs any JARs it needs into your local repository (e.g. ~/.m2/repository). Once installed, the JARs can be used by any other Maven project you build.  The install phase is the default phase if none is specified.

...

That's it! Maven will download all any dependencies the build needs, ; run all unit tests, ; package up the JARs, and ; then install the new JARs locally. For your convenience, copies of the JARs can be found in the target directories of each module. For example, after the build, the main JAR can found at core/target/struts2-core-2.0-SNAPSHOT.jar.

Warning
titleIt's suppose supposed to be automatic, but you might still have to press the button

Sometimes, licensing restrictions prevent Maven for from downloading all the JARs that a build might need. For example, JavaMail and Activation, can only be downloaded from Sun. When this happens, Maven will display a helpful message that explains how to install these JARs manually. After downloading the required JAR, follow the instructions to install it to the your local repository. Once installed, the JAR is availale available to all your Maven builds, not just Struts.

Code Block
titleInitial Build Successful

[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Struts 2 .......................................... SUCCESS [6.016s]
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Struts 2 XWork: Core ........................................................  SUCCESS [01:08.870s086s]
[INFO] Struts 2 - Core ....................................... SUCCESS [12:1742.272s604s]
[INFO] Struts 2Plugins API .......................................... SUCCESS [30.252s944s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 22 seconds
[INFO] Finished at: Wed Jul 19 10:46:01 PDT 2006
[INFO] Final Memory: 10M/42M
[INFO] ------------------------------------------------------------------------

Other phases

There are other phases that can be useful when working with Maven. The package phase will just JAR (or WAR) the modules. The test phase will run only 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 the framework with Maven is to understand build profiles. Profiles provide different configurations for a build. There are several profiles, including default, xwork, and _thirdparty".

Profile

Description

default

Builds site, api, and core

apps

Builds the example applications

plugins

Builds all plugins

extras

Includes the extras module that cannot be part of the default build due to licensing incompatibilties

xwork

Includes the xwork build

Tbe default profile will work for most developers, but some 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
titleProfile, please

> mvn -Pprofile ...

Extras Profile

If you want to build all the extras module not included with the default build, use the _extras*_profile.

Code Block
titleExtras Module

> mvn -Pextras
Code Block
titleBuild with Third Party Modules

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Struts 2  Struts 2 Spring Plugin ............................ SUCCESS [13.523s]
[INFO] Struts 2 Convention Plugin ........................ SUCCESS [16.473s]
[INFO] Struts 2 JUnit Plugin ............................. SUCCESS [13.325s]
[INFO] Webapps ........................................... SUCCESS [1.027s]
[INFO] Blank Webapp ...................................... SUCCESS [9.572s]
[INFO] JBoss Blank Webapp ................................ SUCCESS [7.814s]
[INFO] Mail Reader Webapp ................................ SUCCESS [7.028s]
[INFO] Struts 2 Portlet Plugin ........................... SUCCESS [20.995s]
[INFO] Struts 2 DWR Plugin ............................... SUCCESS [4.432s]
[INFO] Struts 2 Tiles Plugin ............................... SUCCESS [4.451s]
[INFO] Struts 2 Portlet Tiles Plugin ........................... SUCCESS [13.047s741s]
[INFO] StrutsPortlet 2 -Webapp Core ....................................... SUCCESS [3328.615s480s]
[INFO] Struts 2 Struts 1 APIPlugin .......................................... SUCCESS [08.520s353s]
[INFO] Struts Extras 2 Dojo Plugin .............................. SUCCESS [30.181s]
[INFO] Struts 2 JSF Plugin ............................... SUCCESS [206.944s000s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 57 seconds
[INFO] Finished at: Wed Jul 19 10:51:05 PDT 2006
[INFO] Final Memory: 9M/40M
[INFO] ------------------------------------------------------------------------

In the second run, the Extras module is built. If you decide to make use of this module, be sure to review the licenses of its dependencies, since they may be under a license incompatible with the Apache License.

XWork profile

Struts 2 is an extension of the XWork framework. While Struts2 adds a lot of value for web developers, much of the core functionality derives from XWork. The xwork plugins add the capability to build against a current XWork checkout, rather than a precompiled JAR.

The plugin assumes that the latest XWork code is checked out and is located at ../xwork, relative to the struts2 folder. You can check out XWork using the Subversion command:

Code Block
titleChecking out XWork

svn co https://svn.opensymphony.com/svn/xwork/trunk xwork
Tip
titleSubversion

If you don't have the command line version of Subversion installed, you can download it from the Subversion site, and add the bin folder to your command path.

Code Block
titleWorking XWork

> mvn -Pxwork package
Code Block

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] XWork ......Struts 2 Configuration Browser Plugin ............. SUCCESS [7.531s]
[INFO] Struts 2 Sitemesh Plugin .......................... SUCCESS [6.159s]
[INFO] Struts 2 JSON Plugin .............................. SUCCESS [16.944s]
[INFO] Showcase Webapp ................................... SUCCESS [20.303s]
[INFO] Struts 2 REST Plugin .............................. SUCCESS [10.015s]
[INFO] Struts 2 Rest Showcase Example .................... SUCCESS [6.928s]
[INFO] Struts 2 Codebehind Plugin ........................ SUCCESS [10.394s]
[INFO] Struts 2 Java Templates Plugin .................... SUCCESS [9.633s]
[INFO] Struts 2 Jasper Reports Plugin .................... SUCCESS [5.920s]
[INFO] Struts 2 JFreeChart Plugin ........................ SUCCESS [18.296s]
[INFO] Struts 2 Pell Multipart Plugin .................... SUCCESS [3.891s]
[INFO] Struts 2 Plexus Plugin ............................ SUCCESS [4.715s]
[INFO] Struts 2 Sitegraph Plugin ......................... SUCCESS [8.009s]
[INFO] Struts 2 TestNG Plugin ............................ SUCCESS [6.012s]
[INFO] Struts 2 OVal Plugin .............................. SUCCESS [9.629s]
[INFO] Struts 2 OSGi Plugin .............................. SUCCESS [8.118s]
[INFO] Struts 2 Embedded JSP Plugin ...................... SUCCESS [30.524s]
[INFO] Struts 2 GXP Plugin ............................... SUCCESS [4.878s]
[INFO] Struts 2 CDI Plugin ............................... SUCCESS [7.620s]
[INFO] Struts 2 Tiles 3 Plugin ........................... SUCCESS [5.132s]
[INFO] Struts OSGi Bundles ............................... SUCCESS [0.254s]
[INFO] Struts 2 OSGi Admin Bundle ........................ SUCCESS [5.204s]
[INFO] Struts 2 OSGi Demo Bundle ......................... SUCCESS [4.582s]
[INFO] Struts 2 Maven Archetypes ......................... SUCCESS [0.198s]
[INFO] Struts 2 Archetypes - Angular JS .................. SUCCESS [10.509s]
[INFO] Struts 2 Archetypes - Blank ........................ SUCCESS [391.527s440s]
[INFO] Struts 2 Archetypes - Blank Convention .............................. SUCCESS [1.324s]
[INFO] Struts 2 Archetypes - Database Portlet ................ SUCCESS [0.216s990s]
[INFO] Struts 2 Archetypes - Core .................Plugin ...................... SUCCESS [290.736s923s]
[INFO] Struts 2 API Archetypes - Portlet ..................... SUCCESS [0.888s]
[INFO] Struts 2 Archetypes - Starter ...................... SUCCESS [01.318s992s]
[INFO] ------------------------------------------------------------------------ Struts 2 Assembly ................................. SUCCESS [1:37.556s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFULSUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 11 seconds12:23.728s
[INFO] Finished at: Wed JulOct 1930 1017:5726:27 PDTCET 20062013
[INFO] Final Memory: 12M57M/53M945M
[INFO] ------------------------------------------------------------------------

Now, Maven will build XWork from source and use that as the XWork snapshot for the Struts build.

Multiple profiles

Maven can build against multiple profiles. If you are developing against both the XWork and Struts 2 frameworks at once, you can install both profiles with one call to Maven.

Code Block
titleGetting it All

> mvn -Pextras,plugins,xwork

Other phases

There are other phases that can be useful when working with Maven. The package phase will just JAR (or WAR) the modules. The test phase will only execute 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.Using both profiles is especially important when using Maven to build your IDE project files (recommended).

Building IDE project files

...

Code Block
titleStarting over
> mvn idea:idea -Doverwrite=true -Papps,extras,thirdparty,plugins,xwork

If you only need to rebuild some of the modules, adjust the list of "profiles". 

Tip
titleClearing the cache

If you find the xwork module causing you problems, such as displaying as "XWork" when it should be named "xwork", the problem is likely to be within IDEA. Try clearing out your IDEA system cache and then run it again

...

You could also use one of the Maven IDE plugins to run the plugin or simply execute the mvn or mvn.bat file as an external application within your IDEyour IDE.
A good tutorial on how to use the Maven 2 jetty plugin along with your IDE, including JPDA debugging support, can be found at the Apache Wicket documentation.

Maven Tips

A few helpful tips for using Maven are provided:

Offline mode

If you are disconnected from the Internet or simply wish to make your build faster, pass in the -o argument and Maven won't check for new modules to download.

Code Block
titleOffline Mode

mvn -o -Pextras,plugins,xwork

Skipping test execution

Although this shouldn't ever happen, sometimes tests do fail and you need to build the framework anyway. If there's a problem, you can pass in the skip tests parameter.

Code Block
titleSkip Tests

mvn -Dmaven.test.skip=true -Pextras,plugins,xwork

Of course, if you find tests are failing, please submit a patch to fix them!

Debugging build failures

Struts 2 depends on the current snapshot artifact of XWork 2. Unfortunately, if XWork 2 is modified in a significant way, the Struts build doesn't check for and retrieve a new version of the XWork snapshot jar, resulting in compilation or unit test failures.

The solution is to clear out any stale XWork 2 jars in your local Maven repository, usually by removing the directory ~/.m2/repository/opensymphony. This will force the Struts Maven build to pull down a fresh copy of XWork and hopefully resolve your problem.

Creating a release

Maven terms a release build an "assembly". An assembly aggregates the builds of all the modules installed locally on your machine into one or more release files.

To create a release, you must first build and install locally every artifact. From the root struts2 directory, run:

Code Block
titleBuilding all modules

mvn -Pextras,apps,plugins install

Next, you need to run the assembly build to create the release files. From the struts2/assembly directory, run:

Code Block
titleBuilding the assembly

mvn assembly:assembly

Skip exporting pages from Confluence

The whole Struts2 documentation resists on Confluence and during normal build process is exported with SiteExporter tool locally to html files. To perform that, you must have an account on Confluence. In most cases you don't need to export the whole Confluence, so you can skip this, just type command:

Code Block

mvn clean install -DskipWiki

Skip creating assemblies

During normal development cycle you don't need to create assembly packages which consist of all the libraries, example apps and docs - you can skip them as well:

Code Block

mvn clean install -DskipAssembly

Offline mode

If you are disconnected from the Internet or simply wish to make your build faster, pass in the -o argument and Maven won't check for new modules to download.

Code Block
titleOffline Mode

mvn -o

OutOfMemoryError

If you get an OutOfMemoryError while running the tests:

Code Block
titleMemory Settings

// Bash
export MAVEN_OPTS=-Xmx512m

// Windows
set MAVEN_OPTS=-Xmx512m

Skipping test execution

Although this shouldn't ever happen, sometimes tests do fail and you need to build the framework anyway. If there's a problem, you can pass in the skip tests parameter.

Code Block
titleSkip Tests

mvn -Dmaven.test.skip=true

Of course, if you find tests are failing, please submit a patch to fix them!

Debugging build failures

Struts 2 depends on the current snapshot artifact of XWork 2. Unfortunately, if XWork 2 is modified in a significant way, the Struts build doesn't check for and retrieve a new version of the XWork snapshot jar, resulting in compilation or unit test failures.

The solution is to clear out any stale XWork 2 jars in your local Maven repository, usually by removing the directory ~/.m2/repository/opensymphony. This will force the Struts Maven build to pull down a fresh copy of XWork and hopefully resolve your problemIf the assembly built correctly, you should see the release files in the target/assembly/out directory.

Mirrors

The default mirror for Maven builds ("ibiblio") can be slow and unreliable. Maven lets you specify alternative mirrors so that you don't have to depend on ibiblio for everything.

...

In some cases it has been seen that Maven will complain if a module doesn't exist, even though it is part of the current build. Often, the missing module complete turins turns up when executing {mvn package}}. A simple fix for this is to run mvn install instead. If you have to do this, it will probably only be a one - time thing.

Next: Creating and Signing a Distribution