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.
Requirements
To build this project you will need :
- Maven 2.0.x,
- The latest version of BlazeDS-Turnkey or a Tomcat instance.
Dependencies
- 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 3.2.0.3958.
- As an IDE you may use FlexBuilder 3.0.2.xxx, or any text editor.
Multi-module project layout
... +sampleProject -pom.xml ( the parent pom ) +flex-gui -pom.xml +src +main +flex + org.servebox.sample ( All as/mxml sources here ) +resources +test +flex + org.servebox.test.sample ( All classes for unit test here ) +java-service -pom.xml +src +main +java + org.servebox.sample ( All java sources here ) +test +java + org.servebox.test.sample ( All classes for unit tests here ) +web-app -pom.xml +src +main +resources - additional resources for webapp ( such as images, video etc... ) +webapp +WEB-INF +flex -services-config.xml -web.xml
POMs overview
The parent POM
Main section
Parent pom uses the pom packaging (this is an “aggregator project”) :
<modelVersion>4.0.0</modelVersion> <groupId>org.servebox.sample.multi-module-app</groupId> <artifactId>multi-module-sample</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>Flex3-J2EE-MultiModules-Sample-Application</name>
Modules section
The modules section defines the three maven sub-modules :
<modules> <module>flex-gui</module> <module>java-service</module> <module>web-app</module> </modules>
Plugin Repositories and Repositories
The following pluginRepository directive defines the location of the Maven Flex Plugin:
<pluginRepositories> <pluginRepository> <id>servebox</id> <name>ServeBox Plugin Repository</name> <url>http://maven.servebox.org/repository</url> </pluginRepository> </pluginRepositories>
The following repository defines the location of the Flex SDK and ActionScript Foundry dependencies:
<repositories> <repository> <id>servebox</id> <name>ServeBox Plugin Repository</name> <url>http://maven.servebox.org/repository</url> </repository> </repositories>
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 :
<properties> <tomcat.managerurl>http://localhost:8400/manager</tomcat.managerurl> <tomcat.serverprofile></tomcat.serverprofile> <webapp.name>sample-multi-project</webapp.name> <tomcat.server.root>D:\dev\blazeds-turnkey-3.2.0.3978\tomcat\webapps\${webapp.name}</tomcat.server.root> <tomcat.server.user>tomcat</tomcat.server.user> <tomcat.server.password>tomcat</tomcat.server.password> </properties>
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'?> <tomcat-users> <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"/> </tomcat-users>
Download the source code
You may download the source code of this sample from the following location: multi-module-sample-10-snapshot-source
7 Comments to A sample Flex/Webapp project using Maven
Leave a comment
You must be logged in to post a comment.





Gave it a quick skim, very interesting. I’ll be doing something similar to this on my current project very soon.
I have added the parent pom that was missing.
I cant able to find the jar file for the java services module
can any one help me?
Just use “mvn clean install” for building java-service java project.
i find ur module interesting, but i have one problem
when i clean install, i got this error :
java.lang.NullPointerException
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
Hi crofteur,
Could you please open a SR there : http://sourceforge.net/tracker/?group_id=192807&atid=942883.
Could you also run Maven with the -X flag and post into the SR the dependency / plugin dependency tree which will display into your command window ? I think it could be a class loading issue.
Thanks for feedback. Jef.
Buy:Wellbutrin SR.Buspar.Zocor.SleepWell.Nymphomax.Prozac.Benicar.Lipitor.Amoxicillin.Ventolin.Seroquel.Aricept.Female Cialis.Cozaar.Lasix.Female Pink Viagra.Lipothin.Acomplia.Zetia.Advair….