Installing the Adobe AIR 2 SDK in Eclipse

While Adobe makes adding a new Flex SDK easy – just drop a new version folder alongside another version and point Eclipse to the new directory – they make installing a new Air SDK quite frustrating. The Air SDK is installed inside the Flex SDK, so to truly install a new version, you must hijack your existing Flex SDK and replace a few dozen files within the folder structure. It is my sincere hope that Adobe moves away from this coupling and allows Air SDKs to be more easily upgraded in the future without the need to piecemeal copy them onto an existing Flex SDK installation.

Below is short story of how I managed to get my application to build Adobe Air 2.0 applications with Eclipse and the steps I took to resolve the numerous issues that cropped up.

1. Download and Install the Air 2 Runtime and Air 2 SDK

The first step is to download the Air 2 runtime which installs itself within the operating system. The second step is to download the Air 2 SDK, which downloads as a zip file. Assuming you have Flex 2, 3, or 4 installed, there should be a plugin sdks directory that contains an AIR runtime folder such as:

Flex SDK root: C:\Program Files (x86)\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0
Air Runtime root: C:\Program Files (x86)\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\runtimes

Backup (for safety) the runtimes folder and replace it with the one in the Air 2 SDK zip file. Congratulations, you have just installed the Air 2 SDK!

Note: You may have multiple Flex SDK folders on your computer with multiple versions. You should use whichever one your version of Eclipse is pointing to, or create a new version (“3.2.0-air2” for example), and point Eclipse to this new version.

2. Turning on Air 2 within your application

Next, try building and running your Air project within Eclipse using the Flash Builder plugin. Upon launching the compiled application, you will likely see the message “IIMEClient error”:

IIME Client Error

A little bit of digging, shows the error is caused by a combination of the following:

Flash Builder 4 + AIR 2.0 SDK + Application with AIR 1.5 app-descriptor

In short, the app-descriptor for my application (such myApplication.xml) requires that the namespace reference xmlns be changed from

http://ns.adobe.com/air/application/1.5
to http://ns.adobe.com/air/application/2.0

Once you change the version number, the application will compile and run without issue.

3. Full installation of Air 2 SDK required for Release Builds

While you can now build and run Air 2 applications within Eclipse, you will receive an error if you try to Export them as Release Builds. To resolve this issue you go back to step 1 and this time merge all of the files from your Air 2 SDK zip file onto your Flex SDK directory. This is especially risky, since you are replacing dozens of files throughout the SDK, so this time make sure to backup your entire Flex SDK folder. You should expand the zip file and replace over all files and folders.

For example, in the sub-directory bin replace two files from the Flex SDK: adl.exe and adt.bat, but leave the existing files in that folder in place. The rest of the files contained in the zip file should be used to replace the existing SDK files in a similar manner. Many operating systems offer a merge functionality that will only replace the files that have changed and keep the existing files in place.

After you are done, you can open a command window, navigate to the SDK bin folder and type “adt -version” to determine which version of Air is installed. My thanks to Michael Christoff for this part of solution that works on any OS.

The Result

Now you should be able to build, run, and release an Adobe Air 2 application. You can test this by exporting your Air Application to a .air release file, then installing your application using the Air 2 graphical runtime which was installed at the beginning of this process.

what may or may not be in java 7 from the java road trip

Oracle talked about Java 7 at the first stop of the Java Road Trip. The main speaker was Brian Goetz, author of Java Concurrency In Practice.

Despite the disclaimer that everything including syntax is subject to change, the talk was pretty interesting.  Here are my notes.  (this was largely written on my iPad; please excuse any typos)

Modularity

  • The JRE download is 13mb, but most code doesn’t get run by ordinary apps
  • The monolithic jdk makes new releases of platform take longer to roll out
  • Modularizing apps helps with jar hell and finding out at runtime that something is missing/wrong
  • Will provide mechanism for apps to express dependencies in way useful to both humans and tools
  • Based on concepts in Maven and OSGI
  • Current draft has: Module-info.java defining module and version number along with what module and versions or ranges you depend on
  • Classpath will be legacy mode, preferred mode will be to turn your app into a module

Multi lingual support

  • JVM is a managed code environment
  • Scala is a lot like java, but other dynamic languages (like Ruby) run slower because need to rely on reflection or code generation.
  • JVM is more like Smalltalk than like Java , but some places is tied to Java
  • Da Vinci machine project is targeted to adding features to better support dynamic languages. In particular dynamic method linkage which is being able to select version of method based on type of arguments
  • Invokedynamic vs invokevirtual for method selection and linking. Once calls stabilize, don’t look up in vm anymore, then inlines and is as fast as in  java.  This is a goal, need to get there.

Productivity

  • Project coin – add half a dozen small language changes to simplify everyday tasks.  Would be at  level of enhanced for loop
  1. Reduce boilerplate of generics with the the diamond operator (not really an operator)
    Map<String, String> map  = new HashMap<>();
  2. Better numerical literals to make long numbers more readable.  Similarly for binary (long string of 0’s and 1’s)
    long cc= 123_5678_567;
  3. Collection literals – declare inline like we do with arrays and hard coded data.  More declarative. Like associative array in Perl, but may not go that far
  4. Automatically close resources in try/catch.  Better idiom
    try (InputStream in = createInputStream()){
    // code that reads in from stream goes here
    } // compiler will call close for you here

Performance

  • Goal: facilitate scalability across multiple cores
  • Fork join extend recursive action to split into subtasks and join to get answer.
  • Will be added to concurrency utilities.
  • Don’t have to tell it how many cores you have
  • ParallelIntArray class automates common operations filter, map and reduce so can say what want to do declaratively

Closures

  • Saving the best for last.
  • Like anonymous inner classes but without boilerplate of anonymous inner classes
  • Still debating syntax
  • Still debating whether return type should be declared
  • Still discussing how to extend interfaces (will be used to add closures for Collections).  Options are “static extension methods” like in C# where you statically “pretend there were these methods are on the class and call the static methods instead.”  Also discussing ” virtual extension methods.”  Either way the closures project will finally address the issue of api evolution
#(int x)(x*3).domorestuff()

postgresql and jdbc

In postgresql – selecting maximum for each group, we saw the actual stored function.  That was the easy part.  Then there was dealing with Postgresql and JDBC.  I encountered a few surprises while doing this.

Calling the stored function

I expected to use JDBC’s CallableStatement since I was calling a stored procedure.  Nope.  The proper way to call it is:


PreparedStatement stmt = conn.prepareStatement("select * from highlighted_topic_per_forum(?) limit ?");

stmt.setString(1, formattedDate);
stmtp.setInt(2, limit);

Passing a timestamp

Originally, I was passing a timestamp into the stored function by calling stmt.setTimestamp() and a type of “timestamp without time zone”.  Try as I may, postgresql didn’t like this.  It complains $1 not found.  I eventually decided to pass the timestamp as a string.

Passing an array

I was originally planning to pass the category ids via JDBC.  Given what what I experienced with timestamps, I wasn’t so enthusiastic about trying this on an application I work on in my free time.  When I saw the advice online to extend the Array class, I decided to hard code the two category ids.