Ниже мой 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"); // unix "/usr/bin/java"
//window program files/java
info.workingDirectory= File.applicationDirectory;
var args:Vector.<String> = new Vector.<String>();
args.push("-cp","../bin","net.riaspace.Main");
info.arguments = args;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onDataOutput);
// this method will be fired when anything comes from java
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>
И моя главная. Ява
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;
}
}
}
}