Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Invoke Native Process in Adobe AIR 2

0 (0 Likes / 0 Dislikes)
[ringing sound] [ADOBE DEVELOPER CONNECTION] [Christophe Coenraets - Technical Evangelist] Hello, my name is Christophe Coenraets. Today I want to talk to you about a new feature available in AIR 2. [Embedding Tomcat in an Adobe AIR 2 Application] That feature is the ability to invoke native processes so API is exposed by your operating system. To demonstrate that feature, I put together an application that's probably a little different from what you have seen before. Essentially what I did, I embedded Tomcat inside an AIR application. So the use case here is that you have a user that doesn't have Tomcat installed on his or her machine, but you want to provide some of the features made available by Tomcat to your application. So instead of requiring a separate install of Tomcat, you're just going to bundle Tomcat inside the installer of the AIR application. And then from inside that AIR application, you can invoke JSPs locally, you can invoke remote objects, Java objects made available in Tomcat. So I will show you how that works. Here is the console of the application. So the only thing you need to provide is essentially the location of Java on your local machine and we will then start the Tomcat that was packaged as part of the application. Tomcat has been started. As you can see, the console was really made visible inside the AIR application, and from here I could do different things. Like, for instance, if within my application I wanted to invoke a JSP, I would be able to do that. If I wanted to invoke methods of Java objects made available in that Tomcat instance, I would be able to do that as well. So the trick here what was not possible before is that I was able from within an AIR application to actually start a Java process on my local machine, and that Java process essentially started Tomcat. So now that you are familiar with the application, I will show you how you actually do that. Here is the code of the application, so that's all there is to it. The first thing that I'm going to do, and that's probably a best practice, I'm simply going to check that the Native Process API is supported by your runtime because you may potentially try to run the same application within the browser, and that obviously wouldn't work. So the next thing that I will do is the first time the application is executed, I will actually copy the Tomcat that I packaged as part of the installer to your local hard drive in a specific location here. So essentially, I verify if Tomcat is already there. If not, I will copy Tomcat to that location. The next thing I need to do is to actually find the location of the Java Virtual Machine, which is the native process that I will start. So as part of my application, I will actually save that location to an XML file so that I don't have to ask the user all the time for that location. I'm reading my XML configuration file here. If it was not available or if that location is not specified in that file, I will simply, depending on your operating system, offer you some defaults that you can modify. For instance, if you run on Windows, I will assume that Java may be under Program Files, Java, and then a specific version of the SDK. If you run on the Mac, I will offer you this location as a default. And then remember the simple user interface of my application had two buttons, Start Tomcat and Stop Tomcat. Here is what I do. I simply display a message and then I invoke that local function called startNativeProcess with one argument, Start or Stop. And really, the bulk of the process happens in that startNativeProcess method. The first thing I will do is find a path to the Java Virtual Machine, which I do here. Again, I'm going to check if you run on Windows or on a Mac. And then I will add some runtime arguments to start a specific process. For instance, to start Tomcat, I will add the location of Catalina Home, I will provide a class path, different arguments that will be needed. These are equivalent to runtime arguments of my Virtual Machine. And the last thing I pass is going to be the argument provided to the startNativeProcess method, which essentially is going to be either Start to start Tomcat or Stop. And with that, I can use the Native Process API, so I will create an instance of native process, and I will essentially start it, which is, in this case, simply going to start a Java. Of course, you could use any API exposed by your operating system and it would work the exact same way. So then what I will do is simply add two event listeners here to see if that native process is going to output messages. So I will add an event listener to the standard output data and to standard error data. So these event listeners will be triggered every time the native process is sending something to the standard output. I will simply display that message to my console. And that's all there is to it. So this was just one example of what you can do with the Native Process API. You can learn more about that feature by downloading the application on my blog at coenraets.org [Christophe's Blog - coenraets.org] Thank you. [ADOBE DEVELOPER CONNECTION]

Video Details

Duration: 6 minutes and 20 seconds
Country:
Language: English
License: All rights reserved
Genre: None
Views: 176
Posted by: adobetv on Oct 21, 2010

In this video, Technical Evangelist Christophe Coenraets highlights new capabilities of Adobe AIR 2 while exploring the functionality of embedding Tomcat into an application.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.