Using the AWS Flow Java framework with IntelliJ IDEA and Maven

Enabling AspectJ support in Java is a bit of a “love” story in itself. But making sure aspect weaving works for Amazon Simple Workflow in the Maven context (in which, I might say, any developer that operates in a production environment lives and breathes) is a challenge on its own. I’m sharing this article as a result of several days of research, sweat and hair pulling. In short, I am going to explain how to enable compile time weaving for the AWS SWF Flow Java Framework in combination with IntelliJ and Maven. So here goes…

Use JDK 1.7

I highly recommend that you use the Java  1.7 for your project. The best reason to stick with this version is the fact that standard Amazon EC2 and EMR instances come bundled with 1.7 from the very beginning. So you skip a lot of headaches if you keep everything consistent. If you absolutely have to use JDK 1.8, then I feel sorry for you. I started with version 1.8 myself and did not get anywhere with the debugging. After randomly switching dependency and SDK versions, I decided to stick with 1.7 when stuff miraculously started to work.

Install the Flow build tools

The AWS Flow build tools are not yet available as a standalone dependency in the Maven central repository, so you will have to download the AWS Java SDK from the Amazon website and extract the library from there. Because for me the latest version of the AWS Java SDK did not work with AspectJ weaver, I used AWS Java SDK version 1.7.3. I am attaching the specific build tool version here. Once you download the file, install it in your Maven repository:

Creating the pom.xml


The following dependencies are needed for Amazon SWF Flow framework for Java and AspectJ to work properly together:

Tweaking annotation processing

As explained in this post, the AspectJ Maven plugin can do both annotation processing and aspect weaving. While it seems simpler to have one plugin do both APT code generation and compile-time weaving, with this approach complex Flow annotations will be ignored. This is because the AspectJ plugin can only do one thing to a class. This means it can generate client code for workflow and activity interface, weave workflow implementation, but it cannot continue to weave generated activity client code. As a result, some parts of the application, such as elementary activity and decider coordination will work, but you will not see the effects of @ExponentialRetry or @Asynchronous.

To work around this, you have to use a standalone annotation processor so as to specify that annotation processing is to take place in a phase prior to compilation.

You also have to disable further annotation processing in the Maven compiler, in order to avoid class duplication errors. Use the -proc:none compiler argument for this:

Enabling aspect weaving

You are now ready to enable AspectJ weaving for your project. Ensure that you include both the initial sources and the generated annotations in the source path:

Testing it out

If AspectJ compile time weaving is configured correctly, after the compilation the target folder will contain several inner classes which are named AjcClosure#, where # is a digit. Also, you should get messages similar to the one below during compilation:

 Full pom.xml

You can download the full pom.xml file that enables AspectJ weaving with Maven from here.

My environment

For this integration, I’ve been using Mac OSX 10.10.2, Java 1.7.0, Maven 3.2.3, but the workflows themselves have also been deployed to Amazon Linux machines.


Ana Todor is a Computer Scientist with a playful and literary twist. She has a Bachelor of Science degree in Engineering, a Bachelor of Arts degree in Cultural Studies and a Master of Science degree in Computer Science, Digital Interactive Entertainment.

Leave a Reply

Next ArticleUsing the Amazon Elasticsearch Service with Hive