Thursday 1 November 2007

Quickstart flex development with this maven archetype

Have you considered starting some flex development, but haven´t found out where to start? Or are you already flex'ing but could use some easy way to quickstart new flex projects in java?

I have created a maven archetype called maven-archetype-flex and distributed it to ibiblio for all to use.
It will quickly get you up and running.

Here is how you do it:

1. Download flex sdk
Download the flex sdk from adobe, if you haven't got it already.

1b. Minor change to flex-config.xml
You have to uncomment the following in your flex-config.xml located in:

${flex.home}/frameworks/flex-config.xml
<local-fonts-snapshot>localFonts.ser<local-fonts-snapshot>
Otherwise the compiler will complain as Matt mentions in his comment.

2. Create flex project
Running the following maven command will create a flex project called my-flex having groupId my.group. Feel free you change these to what ever you like:
mvn archetype:create
-DarchetypeArtifactId=maven-archetype-flex
-DarchetypeVersion=1.0
-DarchetypeGroupId=dk.jacobve.maven.archetypes
-DgroupId=my.group
-DartifactId=my-flex
-DpackageName=
Note: it is important that you remember the -DpackageName= as the Main.mxml flex file in the archetype is to be kept in the root of your source dir and not in some subpackage.

3. Set flex.home property
In the newly created project pom.xml you should change the flex.home property to fit your flex.home path.

4. Build flex project
Now you are ready to build the flex project:
mvn install
Running this command inside your project will build the project and create a swf file in the target directory.

Viola! You have just created a simple flash application ready to use.

Where to go from here
To see the result of the work you can do one of the following things:
  • Open the flash file with your favorite browser.
  • Download the standalone player for your operating system ().
  • Deploy the swf file to a webserver. Maybe you can get inspiration on how to do it from this maven flex template.

8 comments:

Anonymous said...

@matt:
It is not a Mac/Java/flex thing - even though one could think so in these Mac vs. Java days :-)

I forgot to mention that you have to uncomment the local-font-snapshot element in the flex-config.xml for the sdk.

I have updated the post with information on what to do and it should all work now.

Anonymous said...

Should I be able to change the <sourceDirectory> tag in the pom.xml? No matter what I change it to, I get the error:

Source directory [...]/src/main/flex does not exist.

Anonymous said...

At what time in the process do you get the error?
When creating the project from the archetype? or when calling mvn install in the created project?

Did you remember to set the -DpackageName= to nothing?

If you like you can change the source directory after you have created the project from the archetype. It should not give you any problems. But it is not required that you change the sourcedir.

Anonymous said...

Hi Jacob!

Nice work! Why dont you by default have the flex.home property changed to:

< flex.home > ${env.FLEX_HOME} < /flex.home >

And just ask ppl to set their enviroment variable FLEX_HOME instead. They no change in the pom.xml is needed. =)

One other thing, can I create an actionScript project with this aswell?

Anonymous said...

Hi Jacob,

I have created a project using the mvn archetype as specified. I changed the pom.xml flexhome path to 'C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.0.0'
and when i try to run mvn install from the root folder containing the pom.xml i get the following error.
Build Error - Result of flex2.tools.Compiler execution is: '1'. For more information, run Maven with -3 switch.
Is it an issue with using flex3 instead of flex2 to compile?

Anyway, gr8 work and keep up.
Chears,
Glidealong

Anonymous said...

It was not an issue. I just put the flex.home path at the wrong place. Sorry for the trouble. It's better if you could delete my previous post.
It's working fine now. I would like to know if it's possible to use maven commands from within eclipse IDE?
Thanks a ton.

Anonymous said...

This plugin is goodness. Worked out of the box with maven2, the flex SDK version 3.0 from Adobe, and OSX 10.5.

Greatly appreciate the folks who did this. I like to contribute to projects that make my life easier, find a way to take donations :)

Anonymous said...

I tried this, worked well to create the project but when gave the command for "mvn install" got the following :
C:\flex_mvn>mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: resources. It requires a project with an existing pom.xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Jan 08 10:34:13 PST 2009
[INFO] Final Memory: 3M/254M
[INFO] ------------------------------------------------------------------------