Anvil Flex is on Ohloh.net

February 3rd, 2009
Comments Off

Ohloh is a really great site with interesting metrics on open source projects. Here is the link to Anvil Flex.   It is interesting to look at the analytics, but not sure how where the 67,000 lines of XML come from.  I would believe the 20,000 lines of Action Script though!

Ryan Knight flex

Featured on Drunk on Software

January 21st, 2009
Comments Off

I was on Drunk on Software today.  Had a great talk with Jon Rose and James Ward about Anvil and Enterprise Flex.  This is my first time having my video on the web, but it turned out well.

Ryan Knight flex

An Introduction to Anvil

January 12th, 2009
Comments Off

OVERVIEW

Anvil was designed to help make enterprise flex projects easier and to provide a portal environment for running flex applications. Today Anvil best serves as a sample of how to build enterprise applications. We are working on making it easier to quickly create a customized environment for flex.

What we have found was the biggest challenge with developing a large enterprise framework was how to cleanly divide the application into multiple modules that can be built, maintained and loaded separately. One of the primary challenges with multiple modules is how to cleanly separate the handling of non-visual events. An example would be having one module call a service in another module. Another issue we ran into was how to isolate events with-in a module, especially if there is multiple copies of the same module in an application. An example of this is when you have a portal framework where the user can display the same sub-window multiple times. The standard event dispatcher does not work for these cases and most frameworks do not handle this situation either. For example the popular cairngorm framework was designed to only work in a monolthic environment and event handling gets messed up when you have duplicate copies of a module.

Anvil comes with two sample applications to help you get started. One is a basic sample in the basicSample directory and the other is Anvil Portal in the anvilPortal directory. The biggest difference is the basic sample does not use any security. The anvil/dist directory has pre-built war files so you can easily see what basic Anvil applications look like.

The anvil/dist directory also contains compiled distribution files of the core Shell flex library, the FlexMDI flex library, the shell and utility jar files and the war files for the basic sample and anvil portal.

In the shell directory is the core library files of Anvil for both the Flex and Java side. Then in the layouts directory is the primary visual layout library, FlexMDI, based on code from the Flex Lib project.

The utils directory contains a Java project with a number of utilities for working with Flex. This includes a tool to create ActionScript Data Objects from Java Data Objects. Another utility is Taz, a flex compiler built on top of mxmlc and compc that makes compiling large projects much faster and easier. There are samples of how to call Taz from ant build scripts. And the final utility is a FlexBuilder project file generator.

QUICK START

For the impatient here is a quick overview of setting up the sample applications. Install Java and Tomcat to just run the samples. We have a detailed post on this here. Also install Flex and Ant to build the samples. Be sure to setup the appropriate home environment variables, like JAVA_HOME, CATALINA_HOME, ANT_HOME and FLEX_HOME.

You can copy the sample war files out of the dist directory into your favorite servlet container. Then to run anvil use the following url in your browser:
http://localhost:8080/anvilPortal/

To rebuild the application you can run ant at any directory level. So running ant under shell will re-compile the shell and under anvilPortal will rebuild the sample. Running ant war will rebuild the war files under anvilPortal/build and basicSample/build.

SETTING UP FLEX BUILDER

To setup the Flex Builder project files for any subproject, cd to that directory and modify anvil.conf. Probally the only change will be to where you want it to output files and then run:
ant gen-proj

This will also work from the top level directory.

If you want to reset your project files run:
ant clear-proj

Then in Flex Builder go to file -> import -> other and then under General choose Existing Projects into Workspace. For the root directory first choose shell. Once you have shell imported and build, then import FlexMDI, anvilPortal and basicSample.

USING THE ANVIL UTILITIES

Both the Taz compiler wrapper and the FlexBuilder project file generator use the same config files. The root config file is called anvil.conf and contains the default values, like output directory and the order library files should be compiled in.

Then each project directory has its own config file, like anvilPortal.conf or basicSample.conf. This contains information about each application, module or library.

The files are very short and simplistic, hopefuly making it easy to configure new projects.
To run the taz compiler there is a common ant macro definition in flex.ant.xml called .

For an example of using it see the anvilPortal build.xml file.

To run the actionScript project generators there is a script in the root directory called runAsGen.sh.
This has the following parameters
1 – the input directory of the compiler java class files. By default it is in out/production/shell
2 – the library directories to scan for the necessary jar files
3 – the output directory – this defaults to newAsClasses

BUILDING YOUR OWN APPLICATION BASED ON ANVIL

By using the AnvilPortal framework as a template, you can jumpstart a Flex Application with a Java, Spring, and Spring Security back end. For now it requires a little bit of tedious copy and pasting, but hopefully in the future we can automate it with Maven.

First set up the basic directory structure for your project and then copy in the necessary files from Anvil. The way anvil portal is organized is their is one directory for each module and then inside of there a src/flex and src/java.

As you copy across the files, you will want to get rid of the .svn directories. The easiest way to do this is run this command from the starting directory of the project, before you import it into SVN!
find . -name ‘.svn’ | xargs rm -rf

Be sure to not put a * at the end, that will delete a lot more than expected!

Based on the AnvilPortal sample there are several file and directories we are going to need:

1 – The common ant build files from the anvil/dist:
flex.ant.xml java.ant.xml utils.ant.xml
2 – The config files from anvil/anvilPortal/etc – these are use to configure the basic security and java application options
3 – The /anvil/anvilPortal/web directory – be sure to delete the crossdomain.xml file! These file configure BlazeDS remoting and the starting web page
4 – From the main /anvil/anvilPortal directory copy the following files:
anvil.conf – This file configures the anvil compile process and the eclipse project file generator
common.ant.xml – This defines the common ant build tasks for the project. This makes it easier to reuse ant tasks across multiple modules.
build.properties – This defines the basic build properties
build.xml – The main build file

Now we need to modify the files to fit the new project. Here is a list of recommended changes:

1 – build.properties – change the project.name. Also if you want to use a non-standard directory layout you can change where the files are located in this file. project.root is the parent folder of the project. project.tail is the directory of the current module that is being compiled.
2 – In build.xml change anvil.root to point to the same directory as the project.root (or even better you could do a global search and replace across the entire project and replace anvil.root with project.root).
3 – Now in build.xml change the project name and the name of modules you are defining.
4 – Modify the config files in the etc directory according to your project.

Ryan Knight flex

Intro to flex mojo’s for maven

December 19th, 2008
Comments Off

Velo has put together some nice mojo’s for compiling flex with maven. Here is some quick tips on quickly settings up and using them. Note that you don’t even have to download the mojo’s to use them. They will be automatically downloaded the first time you compile your project.

The first thing to understand is that the mojo’s use the standard maven way of doing things and only use jar files and library files from a maven repository. That means that they don’t look in the flex sdk directory for the necessary files, so these need to be installed in your repository. Also I ran into the problem that compiling on a remote server I ended up needing the data visualization libraries?

First be sure you have the current version of maven, which is 2.0.9:

mvn -version

On the Mac OSX, maven 2.0.6 is installed be default. To upgrade just overwrite the files in /usr/share/maven

Now install all the necessary dependencies in your local repository. These are propietary jar files, so they can be distributed from a central repository.

First cd to your flex sdk directory and the under the lib directory. In there you should a whole bunch of jar files. Then run the following commands:

mvn install:install-file -DgroupId=com.adobe.flex -DartifactId=license -Dversion=3.0.0.477 -Dpackaging=jar -Dfile=license.jar

mvn install:install-file -DgroupId=com.adobe.flex -DartifactId=aglj32 -Dversion=3.0.0.477 -Dpackaging=jar -Dfile=aglj32.jar

mvn install:install-file -DgroupId=com.adobe.flex -DartifactId=flex-fontkit -Dversion=3.0.0.477 -Dpackaging=jar -Dfile=flex-fontkit.jar

mvn install:install-file -DgroupId=com.adobe.flex -DartifactId=rideau -Dversion=3.0.0.477 -Dpackaging=jar -Dfile=rideau.jar

Now it is likely that you will end up needing the data visualization libraries, so do the following.

cd to the flex frameworks dir flex-sdk-3.0.0/frameworks/libs and run the following commands:

mvn install:install-file -DgroupId=com.adobe.flex.sdk -DartifactId=datavisualization -Dversion=3.0.0.477 -Dpackaging=swc -Dfile=datavisualization.swc

then cd to the flex locale dir flex-sdk-3.0.0/frameworks/locale/en_US and run the following commands:

mvn install:install-file -DgroupId=com.adobe.flex.sdk -DartifactId=datavisualization -Dversion=3.0.0.477 -Dclassifier=en_US -Dpackaging=swc -Dfile=datavisualization_rb.swc

Now you are all set to run the flex compiler on your project! I have put a sample pom file here.

Here are a couple of tips to setting up your compile process:

1 – To configure all the different options of the compiler find the option you need on this page and then in your pom add it to the build -> plugins -> plugin (flex-compiler-mojo) -> configuration. For example I set the name of the sourceFile in there.

2 – To add library dependencies, for example swc libraries first add them to your repository. For example to use the flexlib files use the following command similar to this :

mvn install:install-file -DgroupId=com.googlecode.flexlib -DartifactId=flexlib -Dversion=2.4 -Dpackaging=swc -Dfile=flexlib.swc

Then add a dependency tag to your pom. In the sample it is the dependency with the flexlib artifact id.

The types can be one of the following:

external to -compiler.external-library-path

internal to -compiler.include-libraries

merged to -compiler.library-path

rsl to -runtime-shared-library-path for SWF files

caching to -runtime-shared-library-path for SWZ files

test to -compiler.library-path only for test running

Good luck!

Ryan Knight flex

Java and Flex Setup Tips

December 19th, 2008
Comments Off

I have put together fairly extensive instructions on setting up a complete development environment for flex, java and ant. You can read about after the jump.

Jump to Tips on Flex, Java, Tomcat, Ant, Mac OS X and Windows.

OVERVIEW

1) I like to install all the development tools under a common apps directory so they are easier to access from the command line. (i.e. apps on Unix systems or c:apps on Windows). Also there can be problems when accessing the Flex SDK from a directory with spaces in the path.

2) Environment variables on Unix systems (i.e. Mac OS X or Linux) are set with the export NAME=value. For example:

export JAVA_HOME=/apps/jdk1.6.0_04

Here is sample script that sets up all the necessary envrionment variables.

You can set the environment variables for the current window by running the following command:

. ./setjava.sh

FLEX SDK SETUP

The Flex SDK is only needed if your a building the project from the command line. On windows be sure there are no spaces in the path where flex is installed. This will break the build! We are currently using Flex SDK 3.

There are two ways you can set it up:

1) Download it from Adobe.

2) Use the Flex SDK that comes with Flex Builder.

After you have setup the Flex SDK you need to set the FLEX_HOME environment variable:

FLEX_HOME=c:appsflex_sdk_300477

or FLEX_HOME=/apps/flex_sdk_300477

JAVA TIPS

Anvil has been developed with Java 1.6 and is compatabile with 1.5 with some small changes.

When you install the JDK be sure to do a custom setup, so you can install in another directory other than the default which is c:progam files. I recommend using apps for everything.

After installing Java be sure to:

1) Set the JAVA_HOME environment variable to the home directory of java.

2) Add the Java bin directory to the FIRST of the PATH environment variable. There is often several versions of Java on your machine, so it needs to be at the first of the PATH environment variable.

3) From the command line test to be sure the right version of Java is running with the following commands:

a. java –version — This should return Java 1.6

b. on cygwin or Linux you can also run which java to be sure it was installed in the right directory.

SETTING UP TOMCAT

Installing Tomcat is as simple as unzipping it. Be sure to use Tomcat 5 or Later.

See the notes below about using the Tomcat server bundled with Adobe BlazeDS.

1) Download the Tomcat Core zip or tar file.

2) Unzip it into your apps directory (or the directory where you are putting all of your development tools).

3) Set the CATALINA_HOME environment variable to the home directory of where tomcat is. Catalina is just another name for tomcat.

4) To make Tomcat easier to run add the tomcat bin directory to the PATH environment variable. i.e.

export PATH=$PATH:$CATALINA_HOME/bin

or on Windows – %CATALINA_HOME%bin

5) You should now be able to go to the command line and run either:

Linux / Mac OS X varieties – <a href=”http://catalina.sh/”>catalina.sh</a> version

Windows – catalina.bat version

6) To run the Tomcat manager application you need to add an administrative user:

Under the tomcat home directory is a conf directory. In there modify the tomcat-users.xml file.

Add the following line to the file:

&lt;user username=”admin” password=”admin” roles=”manager,tomcat,role1″/&gt;

7) Sometimes when you run Tomcat you will get a conflict with the port it listens on. By default this is port 8080. On Blaze DS the port is changed to 8400. To change this modify the server.xml file in the conf directory.

Modify the line that starts with:

&lt;Connector port=”8080″ Also modify the shutdown port:

&lt;Server port=”8005″ shutdown=”SHUTDOWN”&gt;

Start tomcat from the command line by running:

Linux / Unix vareties – <a href=”http://catalina.sh/”>catalina.sh</a> run

Windows – catalina.bat run

9) You can also start tomcat in a new window by running <a href=”http://catalina.sh/”>catalina.sh</a> start. Tomcat will output the log file to the catalina.out file in the logs directory.

10) To connect to the tomcat manager use the URL:

<a href=”http://localhost:8080/manager/html”>http://localhost:8080/manager/html</a>

Adobe BlazeDS comes with a bundled Tomcat Server. Some things should be noted when using it with Anvil.

1) Under the Blaze DS Tomcat directory is a lib directory. Under there is an activemq4.1.1 directory. The libraries in this directory conflict with the anvil libraries. So this directory either needs to be deleted or moved out of the tomcat directory.

2) BlazeDS Tomcat runs on port 8400 so the URL is localhost:8400

3) Be sure to set the catalina home environment variable to the BlazeDS Tomcat Server, i.e. CATALINA_HOME= C:appsblazeds_b1_121307tomcat

SETTING UP ANT

Installing Ant is as easy as unzipping it. Ant is only needed if you want to build from the source

1) Download Ant and unzip it. It is recommended to put it in the apps directory.

2) Set the ANT_HOME environment variable, i.e. ANT_HOME= C:appsapache-ant-1.7.0

3) Add the ant bin to the PATH environment variable, i.e. %ANT_HOME%bin or $ANT_HOMEbin

4) You should now be able to test ant by running ant -version

JAVA ON MAC OS X TIPS

The latest Mac OS X now has Java 1.6 included, but it is not enabled by default.

2) Java on the Mac OS X is installed into the directory:

/System/Library/Frameworks/JavaVM.framework/Versions

From there you need to specify the version you want to use.

3) The Java binaries are in the Commands directory, instead of the usual bin directory. This breaks a lot of scripts. A simple fix is to cd to the Java home directory and run:

sudo ln -s Commands bin

sudo causes the command to be run with root permissions. ln -s creates a soft link from Commands to bin.

You can then modify the <a href=”http://setup.sh/”>setup.sh</a> script to point to the version of Java you want. Here is my file.

WINDOWS SETUP TIPS

The first tip for setting up Windows would be simply don’t! Move to another platform such as Ubuntu or Mac OS X if at all possible, it makes development so much easier!

1) Setting environment variables on Windows:

a. Right click on my computer or go to control panel and select system.

b. On the dialog box select the advance tab and then select environment variables.

c. Add a new environment variable

d. For example on my machine JAVA_HOME= C:appsjdk1.5.0_07

e. You can reference other environment variables using %NAME%. For example to add the Java bin directory related to the JAVA_HOME environment variable to PATH, you would add – %JAVA_HOME%bin to the FIRST of the PATH environment variable.

2) For Windows I recommend using Cygwin which provides a Linux-Like environment.

a. Download Cygwin and run the installer.

b. When you install cygwin you can change the view in the upper right from packages to full. Some optional packages that are worth installing are:

Subversion

OpenSSH

Ryan Knight flex