A sample Flex/Webapp project using Maven

This is a sample flex3/J2EE project configured as a multi-module maven project. You can use this structure as a basis to build your own project. The Flex project should be considered as a dependency of the Web app project (the WAR). Using the maven dependency plugin, the swf artifact is copied to the web application root folder.

The project contains three modules :

  • flex-gui : the SWF artifact,
  • java-service : a sample Java facade,
  • web-app : the Web application, depending on both the flex-gui and java-services artifacts.

flex-gui project

The “flex-gui” project is a swf flex nature project which contains .as and .mxml source files. This module produces a SWF artifact (packaging: swf).

java-service project

The “java-service” project is a standard java project which contains a java facade, providing data to the GUI. This module produces a JAR artifact (packaging: jar).

web-app project

The “web-app” project is a Web application project that contains  configuration files needed to deploy the application in a container, such as Tomcat. Other resources may also be included, such as JSP, servlet, images… This module produces a WAR artifact (packaging: war).

You can add other modules to create your own project, more often those projetcs could be  dedicated to the business layer, or persistence layer.


To build this project you will need :


  • This sample is based on the Maven Flex Plugin 2.1.1. Check the homepage of the project to see more.
  • The Flex SDK version used is
  • As an IDE you may use FlexBuilder 3.0.2.xxx, or any text editor.

Multi-module project layout

      -pom.xml ( the parent pom )
              + org.servebox.sample ( All as/mxml sources here )
              + org.servebox.test.sample ( All classes for unit test here )
              + org.servebox.sample ( All java sources here )
              + org.servebox.test.sample ( All classes for unit tests here )
              - additional resources for webapp ( such as images, video etc... )

POMs overview

The parent POM

Main section

Parent pom uses the pom packaging (this is an “aggregator project”) :


Modules section

The modules section defines the three maven sub-modules :


Plugin Repositories and Repositories

The following pluginRepository directive defines the location of the Maven Flex Plugin:

            <name>ServeBox Plugin Repository</name>

The following repository defines the location of the Flex SDK and ActionScript Foundry dependencies:

            <name>ServeBox Plugin Repository</name>

The Build Section

Importing projects into the Eclipse / FlexBuilder workspace

Maven can generate the eclipse project properties files for flex and java nature trought the maven eclipse plugin and maven flex plugins. Download the sample project, extract it into your workspaces directory, create a new workspace for the multi project and run the following command line from the root folder of the multi-module project (the root of the Maven reactor).

mvn flex:eclipse eclipse:eclipse

After importing “existing project” into a workspace, you have to define M2_REPO variables available to flex and java, see the next two screenshots :

Building the project

First, you have to define properties in the pom.xml of the root project :


You should replace the values with those corresponding to your own environment.

The whole project may be built using a single command. Using a command-line shell, run “mvn clean install” from the root folder : all projects included in the reactor will be built and installed to your local Maven repository (by default ~/.m2/repository).

If you want the application to be deployed automagically in tomcat, use the goal “tomcat:exploded”, and make sure that :

  • your Tomcat instance is running,
  • the configuration file ${tomcat.root]/conf/tomcat-users.xml contains the “tomcat” user (this profile is used by Maven to manage the Tomcat instance) :
<?xml version='1.0' encoding='utf-8'?>
  <role rolename="tomcat"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat,admin,manager"/>
  <user username="admin" password="" roles="admin,manager"/>

Download the source code

You may download the source code of this sample from the following location: multi-module-sample-10-snapshot-source

Tags: , ,

Print This Post Print This Post Monday, January 19th, 2009 Tutorials by Jeff Mathiot

6 Comments to A sample Flex/Webapp project using Maven

  1. Gave it a quick skim, very interesting. I’ll be doing something similar to this on my current project very soon.

  2. pwilder on January 20th, 2009
  3. I have added the parent pom that was missing.

  4. Alexis Desmarais on January 26th, 2009
  5. I cant able to find the jar file for the java services module
    can any one help me?

  6. kalyankrishna on July 10th, 2009
  7. Just use “mvn clean install” for building java-service java project.

  8. Alexis Desmarais on July 10th, 2009
  9. i find ur module interesting, but i have one problem

    when i clean install, i got this error :

    at org.codehaus.plexus.util.xml.Xpp3Dom.(Xpp3Dom.java:73)
    at org.apache.maven.lifecycle.LifecycleUtils.mergeBindings(LifecycleUtils.java:304)
    at org.apache.maven.lifecycle.plan.BuildPlan.addLifecycleOverlay(BuildPlan.java:129)

    if u can help me;) thx

  10. crofteur on December 4th, 2009
  11. Hi,

    i have an error when executing mvn flex:eclipse eclipse:eclipse

    [INFO] ————————————————————————
    [INFO] Reactor Summary:
    [INFO] Flex3-J2EE-MultiModules-Sample-Application …….. SUCCESS [26.555s]
    [INFO] flex-gui …………………………………… FAILURE [21.820s]
    [INFO] java-service ……………………………….. SKIPPED
    [INFO] web-app Maven Webapp ………………………… SKIPPED
    [INFO] ————————————————————————
    [INFO] ————————————————————————
    [INFO] Total time: 3:55.765s
    [INFO] Finished at: Thu Jun 09 16:50:04 CEST 2011
    [INFO] Final Memory: 9M/23M
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.servebox.flex:flex-plugin:2.1.0:eclipse (defa
    ult-cli) on project flex-gui: The property serverRoot should be set. -> [Help 1]

    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
    rg.servebox.flex:flex-plugin:2.1.0:eclipse (default-cli) on project flex-gui: Th
    e property serverRoot should be set.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    Caused by: org.apache.maven.plugin.MojoExecutionException: The property serverRo
    ot should be set.
    at org.servebox.flex.mojo.EclipseMojo.checkServerConfiguration(EclipseMo
    at org.servebox.flex.mojo.EclipseMojo.execute(EclipseMojo.java:261)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    … 19 more
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
    [ERROR] After correcting the problems, you can resume the build with the command

    [ERROR] mvn -rf :flex-gui


  12. nillak on June 9th, 2011

Leave a comment

You must be logged in to post a comment.