Automated DTO Generation with Maven and GAS3


In Recent years Flex has become the ideal client solution for Java server based projects. Flex compliments Java in many ways and has many similarities to Java. These include, the syntax, the OOP approach and many other features of the two languages that are similar.

In this tutorial, I will demonstrate one aspect of the Flex Java integration by covering the earliest stage of the development process, which is the build and infrastructure creation. In future posts I will cover later stages of the development.


VO\DTO Generation
The VO generation process converts the existing server side entity classes to client side entity classes. At the end of the process each server side DTO\Entity class will have a client side corresponding class, enabling easy communication between the client and server.


Using GAS3 to Generate AS3
GAS3 is one the modules of GraniteDS, GDS is a comprehensive Flex remoting framework which will not be covered in this post. GAS3 is responsible for the Java to AS3 VO (or DTO) generation, it reads the domain Java objects and generates the corresponding AS classes. Usually GAS3 is used in conjunction with other GraniteDS modules. However, as I'm about to demonstrate, GAS3 can also be used separately from GDS in conjunction with different remoting frameworks such as BlazeDS or even different integration layers like SOAP and REST services.

GAS3 is created on top of the Groovy templates. It can be customized and used to generate different derivatives of Vos.


MyCRM Sample Application
The sample mini application shown below, is a CRM app (MyCRM). responsible for managing customer information ,it contains three sub projects, as follows:


mycrm-core: The Java server, responsible for the server side business logic. In our sample it contains only a number of basic entities.
mycrm-parent: Maven's parent project, which serves as a parent POM.
mycrm-flex-domain: The Flex side of the domain objects, packaged as an SWC which may be used by any Flex application.

The entire code for the sample application may be downloaded from here


The GAS3 Maven\Ant Build Tag

update (thanks to velo) : it looks like flexmojos now has GAS3 integration so you don't need to use the Ant runner tag

In the pom.xml under mycrm-flex-domain, the following section is responsible for the GAS3 operation:

<gas3 outputdir="../mycrm-flex-domain/src" tide="true"
location="../mycrm-core/target/classes" />
<include name="net/flexonjava/examples/mycrm/domain**/*.class" />

Many of the tags above are overrides for the default configurations, you can use them in order to override GAS3 default settings. Lets take a closer look on some of these settings:


GAS3 generates two types of VOs, the Base class and the class extends Base. Do not touch the Base class, this class is auto-generated every-time you compile, it’s best practice not to include it under your source control management repository. The child class is a different story, this class is simply a wrapper that you are welcome to modify. It can be used for different purposes, such as, validating setter values, annotating, in-line documentation and so on. If you were wondering, The class is also auto-generated like the Base class, Only if a copy of the class is not yet available in your code.

The baseoutputdir tells GAS3 to place the base classes in a place different then my src folder.


GAS3 uses Groovy templates to convert Java to AS3 classes. GSP (Groovy Server Page) code is used in these templates. GSP is very similar to JSP or any other script language you’ve probably used in the past. By writing your own templates or modifying the existing ones you can modify the generated AS3 classes to suit your needs. You can insert your custom code remarks or apply your own logic on the conversion process. The default templates maybe found under GAS3 distribution (look for *.gsp file name extension). I made some modifications to the basic templates.

When the build is ready and configured, run mvn clean install. If everything goes well, a new SWC will be created for the mycrm-flex-domain project. This SWC will be used by any Flex project that needs to talk with MyCRM server. The SWC maybe used in conjunction with BlazeDS, SOAP, REST or any other integration layer we would like to use.


This article was also published on my blog


Special thanks to Gad who worked with me on this.

Thank you for your interest!

We will contact you as soon as possible.

Want to Know More?

Oops, something went wrong
Please try again or contact us by email at
Thank you for your interest!

We will contact you as soon as possible.

Let's talk

Oops, something went wrong
Please try again or contact us by email at