Home > ActionScript, Flex, Maven > Java classes to Actionscript3 classes using Maven 2

Java classes to Actionscript3 classes using Maven 2

At some point I found myself in a situation where I had data objects in Java and in order to use the same objects in Flex application I had to duplicate these classes in Actionscript 3. It was pretty boring and in addition to that, the possibility to forget to add or change some attribute was very high and it happened of course more than once. As I started to look around in web I had very low expectations to find a tool for converting Java classes to Actionscript classes. After some digging I found that actually there is a great tool, which does exactly what I needed.

Franck Wolff had created an Actionscript generator which can be run as an Ant task and you only have to define the source directory where your compiled Java classes are located and the destination directory where you want the generated Actionscript classes to have and that’s it. As I was more used to Maven and couldn’t spend too much time on the topic I decided to use the Maven’s Ant plugin to call the generator from pom.xml (an example how I use it can be seen below).

– compile the Java classes in my web application
– call the Actionscript generator to take the compiled Java classes and generate Actionscript out of them
– call the Flex compiler to compile the Flex application with the generated classes (you can get a more detailed view of this and following points – also here)
– call the maven-flex2-plugin to copy the compiled Flex app to my web application module
– package all together to a war file
– deploy it to Tomcat server
Ok, there was also some other stuff too like generating hibernate mappings and adding functionality to generated Actionscript classes but I’ll try to write about it soon. Great thing was that all of it actually worked and I had the possibility to configure this tool the way I wanted.

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <tasks>
                    <taskdef className="org.granite.generator.ant.As3BeanAntTask" name="gas3" />
                    <gas3 outputdir="../flex/src">
                        <classpath>
                            <pathelement location="target/classes" />
                        </classpath>
                        <fileset dir="target/classes">
                            <include name="ee/quest/model/question/*.class" />
                        </fileset>
                    </gas3>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>1.5.3</version>
            <scope>compile</scope>
        </dependency>
          <dependency>
            <groupId>org.granite</groupId>
            <artifactId>granite-generator</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.granite</groupId>
            <artifactId>gas3</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</plugin>
Advertisements
Categories: ActionScript, Flex, Maven
  1. antoine
    03/04/2009 at 8:15 am

    Hey, nice time saving tool.
    How could I use your maven plugin, is it available on a repository ?
    I guess not, how can I install it in local ?

    Thx

    • akopparthi
      03/05/2009 at 6:47 pm

      First of all it is not something i invented,I have been looking for this. I have used several elipse plugins like j2as and some ant tasks, but, I find this is simple and i have implemented this in my project.
      all the jars that i have referenced are available from maven repository. Just in case if you want to install all the dependencies in your local. follow this.

      http://download.java.net/maven/2/org/graniteds/

      if you have some time you can get these maven plugins from google-mojo’s

  2. Vijay
    10/20/2009 at 11:54 pm

    Hey what data services are you guys using, I am having problems with data mappings when i use the generated code for blazeds. Obviously since i dont have Imap and others. How do we get the custom type mapping to work.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: