AIR Application with Embedded Tomcat

In this sample application, Tomcat and BlazeDS are embedded as part of the native installer. The first time you run the application, Tomcat is automatically copied to your applicationStorageDirectory from where the AIR application starts it. You can start and stop Tomcat manually from within the application, but in a real life application you would probably want to start Tomcat automatically when the AIR application starts.

Why would you want to embed Tomcat as part of an AIR application? First of all, I’m not saying that you should… This was just part of my exploration of new capabilities in AIR 2.0. That being said, I can think of a number of use cases where this could make sense. For example:

  • Tighter communication with Java code using BlazeDS locally as a way to directly invoke methods on remote Java classes.
  • Provide an offline mode for an application that closely mimics the online infrastructure.

Installation Instructions

  1. Make sure you have the AIR 2 runtime installed (you can download it here).
  2. Because Tomcat Launcher uses the Native Process API, you have to use one of the native installers available below
  3. After starting the application, enter the path to your Java home folder, then click the Start button. The application will remember the folder you entered the next time you use the application. Try the “Embedded JSP Example” and “Embedded RemoteObject Example”. If you get a BindingException when you start Tomcat, make sure it isn’t already started. You can also click the Stop button to stop a running instance.

Downloads

Windows Installer AIRAppWithEmbeddedTomcat.exe 07/09/2010
Mac Installer AIRAppWithEmbeddedTomcat.dmg 07/09/2010
Project file AIRAppWithEmbeddedTomcat.fxp.zip 07/09/2010

Comments

  1. Juan Quiroga says:

    excelent post, and project, i didn’t know, that air, have support to make a web server!! and embebed one of them!!! :D
    how long do you have working with flex ??

    thanks!!

  2. Stephen says:

    What is the password to the source zip file? Thanks for doing this – can’t wait to look at the code!

  3. Daniel Wind says:

    Excellent tutorial. Thanks for sharing….

  4. micro says:

    good

  5. Tsai says:

    The error is shown when I start the Tomcat. Do you have any advise for this? Thank you.

    Starting Servlet Engine: Apache Tomcat/6.0.20
    **** MessageBrokerServlet in application ‘undefined’ failed to initialize due to runtime exception: Exception: flex.messaging.config.ConfigurationException: Please specify a valid ‘services.configuration.file’ in web.xml. You specified ‘/WEB-INF/flex/services-config.xml’. This is not a valid file system path reachable via the app server and is also not a path to a resource in your J2EE application archive.
    at flex.messaging.config.ServletResourceResolver.isAvailable(ServletResourceResolver.java:54)

  6. Joshua Cane says:

    This is very promising and I appreciate the sample. I have two questions and appreciate any help you can offer:
    1. How did you add Tomcat to the AIR project in Flash Builder? In other words, if I were to make an AIR project from scratch, how would I add Tomcat to it? Do I just copy the Tomcat files into it? Or something else?
    2. I tried making a second .jsp file in the web root where your hello.jsp exists, but when pointing to that file instead, I get an error, file not found. What am I doing wrong?

    Thank you again,
    Josh Cane

  7. Mino says:

    Hi, Thanks for this.
    Did you know that the ‘classes’ folder inside a web app is not copied into the output folder?
    is this a standard adobe air behavior or some param to set?

    Thanks in advance for your help.

    -Mino

  8. Luke Evans says:

    Is using a native installer the only way to do this? We want to be able to use the Air update functionality to be able to update the apps we deploy to the embedded Tomcat we deploy

Speak Your Mind

*