i’m using Flex 4 Native Process to interact with Java to connect to a remote server using PHP.
I tried this example i found on the internet to connect Flex with Java:
Flex:
protected function windowedApplication1_creationCompleteHandler(event: FlexEvent): void
{
var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
info.executable = new File("C:/Program Files/Java/jre6/bin/java.exe");
info.workingDirectory = File.applicationDirectory;
var args: Vector.<String> = new Vector.<String>();
args.push("-cp", "../bin", "scanner.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);
}
Java:
public static void main(String[] args)
{
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! ... from java");
}
else if (input.equals("stop"))
{
return;
}
}
}
And it works perfect.
But when i try calling the Java method that connects to the remote server, switching the line System.out.println("hello flex! ... from java"); for the name of the method, it dies (does nothing).
I’m new to the Native Process concept, but researching on the web i found out that you need to send the libraries as arguments that your project uses.
I need some help on how to do so.
The Java project uses Http and JSon libraries.
How do i add those to the arguments? and do i need to add the JRE System libraries too?
PS: The java method works fine if i execute it from eclipse.
Thank you.
Edit: Tried it with a Jar file
var file:File = new File("C:/Program Files/Java/jre6/");
file = file.resolvePath("bin/javaw.exe");
var arg:Vector.<String> = new Vector.<String>;
arg.push("-jar");
arg.push(File.applicationDirectory.resolvePath("prueba3.jar").nativePath);
arg.push("-Djava.library.path=C:\\Users\\Administrador\\Desktop\\libhttp");
var npInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
npInfo.executable = file;
npInfo.arguments = arg;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
process.start(npInfo);
and adding the library path, but still didn’t work.
You could make a AMFPHP service, and connect directly to PHP with AS3