0 Replies Latest reply on Mar 14, 2011 2:42 PM by gunalexia

    Air and Java Integration

    gunalexia

      I am developing an air application,

       

      below is my JavaProcess.mxml

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication

       

       

      xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="

      library://ns.adobe.com/flex/spark"

      xmlns:mx="

      library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

      creationComplete="windowedapplication1_creationCompleteHandler(event)"

      >

       

       

      <fx:Script>

      <![CDATA[

       

       

      import mx.events.FlexEvent;

       

      import mx.controls.Alert;

       

      protected var process:NativeProcess;

       

       

       

      protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void

      {

       

       

      var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();// holds all info about native process

      info.executable =

       

      new File("C:/program files/java\/jre1.6.0_22/bin");

       

       

      //window program files/java

       

      info.workingDirectory= File.applicationDirectory;

       

       

      var args:Vector.<String> = new Vector.<String>();

      args.push(

      "-cp","../bin","net.Main");

      info.arguments =args;

      process =

      new NativeProcess();

      process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onDataOutput);

      process.start(info);

      }

       

       

      private function onDataOutput(event:ProgressEvent):void

      {

       

       

      var message:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);

      Alert.show(message);

      }

      ]]>

       

      </fx:Script>

       

       

      <fx:Declarations>

       

       

      <!-- Place non-visual elements (e.g., services, value objects) here -->

       

       

      </fx:Declarations>

       

       

      <s:Button label="call java" click="process.standardInput.writeUTFBytes('hello\n')"/>

       

      </s:WindowedApplication>

       

      and here is the Main.java

      package

       

       

       

       

       

      net.riaspace;

       

      import

       

       

       

       

       

      java.util.Scanner;

       

      public

       

       

       

       

       

      class Main {

       

       

      /**

      *

       

      @param args

      */

       

       

      public static void main(String[] args) {

       

      // TODO Auto-generated method stub

      String input;

      Scanner scanner =

       

      new Scanner(System.in);

       

       

      while(scanner.hasNext("Hello|stop"))

      {

      input = scanner.next();

       

      if(input.equals("hello"))

      {

      System.

      out.println("Hello Flex");

      }

       

      else if(input.equals("stop"))

      {

       

      return;

      }

      }

       

      }

       

      }

       

       

      I saw the above code from "riaspace"

      " video . I am working on windows machine and the above code doesnot work. The error I am getting is "ArgumentError: Error #3214: NativeProcessStartupInfo.executable does not specify a valid executable file" ,

       

      the path to java executable file I tried are

       

      1. new File("C:/program files/java/jre1.6.0_22/bin");

      2. new File("C:/program files/java/jre1.6.0_22/bin/java.exe");

      3.new File("C:/windows/system32");

      4.new File("C:\\program files\\java\\jre1.6.0_22\\bin");

       

      nothing works... anyone pls help.. Thanks in advance.

       

      My project workspace is " c:\Documents and settings\username\MyDocuments\MainFolder"  , may be that changes?