Skip navigation
Prathvi_palelar
Currently Being Moderated

Invoking Java Process

Jul 9, 2010 12:26 AM

I am successfully running the Application show in the following link
http://tv.adobe.com/watch/adc-presents/invoking-java-process-from-adob e-air-2-applications/
i.e Invoking Java Process from Air Application .

the application runs on Flash Builder 4

but when i create Native Installer and run the app after installation it is unable to invoke java process.

 
Replies
  • Currently Being Moderated
    Jul 21, 2010 1:43 PM   in reply to Prathvi_palelar

    What error do you encounter?  This might help shed some light on the issue, depending on what the issue is:

     

    http://aaronhardy.com/flex/javautils-detecting-and-installing-java-fro m-air/

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 22, 2010 1:43 AM   in reply to Prathvi_palelar

    Hi there,

     

    I've recently run into exactly the same problem, although I wish I had seen that video!

     

    If the Java process is starting when run from within Flash Builder, but failing after exporting release build:

     

    You need to use ADT to compile the .air file into a native executable for NativeProcess to work.

     

    You can find more information on doing this at: http://help.adobe.com/en_US/air/build/WS789ea67d3e73a8b22388411123785d 839c-8000.html

     

    The simplest method of compiling to a native executable (which compiles without using a developer license is

     

    adt -package -target native <URL_of_Destination_executable_file> <URL_of_AIR_file>

     

    e.g. adt -package -target native C:\myapp.exe C:\myapp.air

     

    If the Java process is not starting when run from within Flash Builder:

     

    1. Ensure you have included the extendedDesktop profile in the supportedProfiles section of your main-app.xml

     

    eg: <supportedProfiles>extendedDesktop desktop</supportedProfiles>

     

    2. Ensure you are starting the NativeProcess correctly:

     

    e.g.

     

     

    
    private var process:NativeProcess = new NativeProcess();
    private var args:Vector.<String> = new Vector.<String>();
    private var processStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    private var javaPath:File = new File("C:\PathToJava.exe");
    private var jarFilePath:File = new File("C:\PathToJarFile.jar");
    // Use working directory if there are sub-folders the java process needs to access (for example a config folder)
    private var workingDirectory:File = new File("C:\WorkingDirectory");
    
    private function startJava():void {
        // This needs some checking to make sure the files actually exist (file.exists)
        processStartupInfo.executable = javaPath;
        processStartupInfo.workingDirectory = workingDirectory;
        processStartupInfo.arguments.push("-jar", jarFilePath.nativePath);
    
        // Add event listeners
        process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
        process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
        process.addEventListener(Event.STANDARD_ERROR_CLOSE, standardErrorClose);
        process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
        process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
        process.addEventListener(Event.STANDARD_INPUT_CLOSE, standardInputClose);
        process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onIOError); 
        process.addEventListener(Event.STANDARD_OUTPUT_CLOSE, standardOutputClose);
        process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
    
        process.start(processStartupInfo);
    }
    
    /*------------- Java Process Event Listeners -----------------*/
    private function standardOutputClose(evt:Event):void {
        trace("Java: [CLOSED] due to output.");
    }
                 
    private function standardInputClose(event:Event):void {
        trace("Java: [CLOSED] due to input.");
    }
                 
    private function standardErrorClose(event:Event):void {
        trace("Java: [CLOSED] due to Error.");
    }
                 
    private function onOutputData(event:ProgressEvent):void {
        var outputText:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
        trace("Java: " + outputText); 
    
    }
                 
    private function onErrorData(event:ProgressEvent):void {
        trace("Java: [ERROR] " + process.standardError.readUTFBytes(process.standardError.bytesAvailable));           
    }
    
    private function onExit(event:NativeProcessExitEvent):void {
        trace("Java: [EXIT] with code", event.exitCode);
        DADEventManager.Dispatcher.dispatchEvent(new JavaEvent(JavaEvent.MERAPI_SHUTDOWN));
    }
                 
    private function onIOError(event:IOErrorEvent):void {
        trace("Java: [IOERROR] " + event.toString());
    }
    /*------------------ End of event listeners ------------------*/
    
    
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points