Versions Compared

Key

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

...

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.

Build profiles

The next step in 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 incompatibilities

xwork

Includes the xwork build

The default profile will work for most developers; however some developers will want to use additional profiles because they work on both XWork and other modules, such as the JasperReports integration.

Specifying a profile is easy:

Code Block
titleProfile, please

> mvn -Pprofile ...

Extras Profile

If you want to build all the Extras module (not included in 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 .............................................. SUCCESS [1.047s]
[INFO] Struts 2 - Core ....................................... SUCCESS [33.615s]
[INFO] Struts 2 API .......................................... SUCCESS [0.520s]
[INFO] Struts Extras ......................................... SUCCESS [20.944s]
[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 fall under a license that is 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 is derived from XWork. The xwork plugins add the capability to build against a current XWork check-out, rather than a pre-compiled 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 ................................................. SUCCESS [39.527s]
[INFO] Struts 2 .............................................. SUCCESS [0.216s]
[INFO] Struts 2 - Core ....................................... SUCCESS [29.736s]
[INFO] Struts 2 API .......................................... SUCCESS [0.318s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 11 seconds
[INFO] Finished at: Wed Jul 19 10:57:27 PDT 2006
[INFO] Final Memory: 12M/53M
[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

Using both profiles is especially important when using Maven to build your IDE project files (recommended).

Building IDE project files

Maven has a great feature that will allow you to build up your IDEA or Eclipse project files based on the project build structure. Using the Maven project files helps keep developers in-sync and efficient. The IDEA project files are pre-configured to define in the Run/Debug menu many common tasks, such as "execute all tests", "launch the showcase sample app", and so fort.

IDEA by JetBrains

The Maven IDEA plugin creates IDEA project and modules files, based on the Maven build configuraton (pom.xml).

First, be sure you have the latest IDEA plugin for Maven.

Code Block
titleGet the latest plugin!

mvn -DconnectionUrl=scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-idea-plugin \
    -Dgoals=install \
    scm:bootstrap

Most often, we use Maven to build projects, but it can also run plugins directly. To build an IDEA project file for Struts 2, including all the modules, run

Code Block
titleGenerate the project files

> mvn idea:idea -Papps,extras,thirdparty,xwork

Maven will generate struts-parent.ipr, struts-parent.iws, and an iml file for each module listed Open up struts-parent.ipr in IDEA, and you should be good to go.

If you ever need to rebuild your projects, running the idea:idea command again will update your files without overriding any information that doesn't conflict. If you do want to overwrite the project files, specify the overwrite parameter as true.

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

Eclipse

For Eclipse, try

Code Block
titleGenerating Eclipse

> mvn -Pthirdparty,plugins,xwork eclipse:eclipse
Info
titleFeedback Wanted

Many Struts 2 developers use IDEA, and the Eclipse project files are not as well-tested or featureful as the IDEA versions. But as far as we know, they work!

IMPORTANT: Running the Sample Applications from Eclipse or non-IDEA IDEs

Currently the sample applications can be deployed using the Maven 2 Jetty plugin. For example, you can run the showcase example application from the command line:

Code Block
titleRunnning Showcase in Linux

cd apps/showcase
mvn jetty:run

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 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

...

Building IDE project files

Maven has a great feature that will allow you to build up your IDEA or Eclipse project files based on the project build structure. Using the Maven project files helps keep developers in-sync and efficient. The IDEA project files are pre-configured to define in the Run/Debug menu many common tasks, such as "execute all tests", "launch the showcase sample app", and so fort.

IDEA by JetBrains

The Maven IDEA plugin creates IDEA project and modules files, based on the Maven build configuraton (pom.xml).

First, be sure you have the latest IDEA plugin for Maven.

Code Block
titleGet the latest plugin!

mvn -DconnectionUrl=scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-idea-plugin \
    -Dgoals=install \
    scm:bootstrap

Most often, we use Maven to build projects, but it can also run plugins directly. To build an IDEA project file for Struts 2, including all the modules, run

Code Block
titleGenerate the project files

> mvn idea:idea -Papps,extras,thirdparty,xwork

Maven will generate struts-parent.ipr, struts-parent.iws, and an iml file for each module listed Open up struts-parent.ipr in IDEA, and you should be good to go.

If you ever need to rebuild your projects, running the idea:idea command again will update your files without overriding any information that doesn't conflict. If you do want to overwrite the project files, specify the overwrite parameter as true.

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

Eclipse

For Eclipse, try

Code Block
titleGenerating Eclipse

> mvn -Pthirdparty,plugins,xwork eclipse:eclipse
Info
titleFeedback Wanted

Many Struts 2 developers use IDEA, and the Eclipse project files are not as well-tested or featureful as the IDEA versions. But as far as we know, they work!

IMPORTANT: Running the Sample Applications from Eclipse or non-IDEA IDEs

Currently the sample applications can be deployed using the Maven 2 Jetty plugin. For example, you can run the showcase example application from the command line:

Code Block
titleRunnning Showcase in Linux

cd apps/showcase
mvn jetty:run

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 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:

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.

...