views:

110

answers:

6

Thinking outside of the box here...

What possible basic approaches could be taken in an effort to create a Flex component that could run Java?

I know I can easily use flex to browse to or launch a Java app, but there are things I can only do if I can run the Java from WITHIN an MXML Component.

I the strictest sense, I know it's not impossible (ie: if you had all the source code for flex and for the jvm), but what's the least impractical means to this end?

Edit: Lots of people are interested in the reason WHY someone might want to do this. I see it as irrelevant to HOW to do it, but here goes: I have over 100 proprietary pixel-reading windows programs that I could port to Mac in this way, much easier than any other way. But instead of arguing the premises, the winning answer will ignore the reasons why, and focus on the HOW.

Showcase your creativity.

+1  A: 

This sounds crazy insane to me. My answer is to not go down this route. It may be a fun technical challenge for fun; but has little practical value that I can see.

Answer the question, Why would you want to run a JVM inside a Flex app?

Also, How would you use a Flex App to browse or launch a Java App? As best I understood, the security sandbox of the browser prevents you from launching other local applications.

www.Flextras.com
A: 

I'm with Flextras, you need to explain why before a reasonable solution can be proposed.

Unreasonable solution:

Implement the jvm in AS3. Read jars in as bytearrays. Pass the bytearrays to you new jvm.

Reasons for unreasonableness:

  • Implementing even a partial jvm would be at least thousands of man hours of work.
  • Running a virtual machine inside of Flash's already (relatively) slow vm would be like riding a golf cart that's being towed by a tortoise: either one by itself would be faster.
justkevin
A: 

Yeah, you really need to tell us why you want this, as it greatly influences what solutions might be feasible.

Dusty J
A: 

A while back I prototyped something like this. I exposed a window / native app via a VNC server and then used an open source VNC client library to connect to the VNC server. It was totally hacky but it worked. Performance was not great but was usable. Here is the Flash VNC client library I used: http://www.wizhelp.com/flashlight-vnc/index.html

James Ward
A: 

You can interface between Air & a Java app using merapi (although that's just communication, not actually running the api inside air)

quoo
+1  A: 

I don't believe you are correct about not being able to accomplish certain things you "can only do if I can run the Java from WITHIN an MXML Component". With proper communication set up, you can have the Applet and the SWF simply communicating with each other through an external set of processes.

The easiest way to accomplish this is to "fake it". Load a Java Applet (This should be possible by use of the SWF's ExternalInterface API -- generate the Object tag and add it to the HTML around the swf. To make this even more convincing, use CSS to have to Applet appear "on top" of the swf. ) and have it communicate with the original swf through JavaScript calls. If that is not possible, then it may be possible to have the Java Applet generate some form of pseudo-server which the swf could then communicate with.

If neither of those work, then there is always the SWF bytearray syntax. It would need to load a ByteArray, manipulate the internal data, and then send it... somehow.

Christopher W. Allen-Poole
RE: I don't believe you are correct about not being able to accomplish certain things you "can only do if I can run the Java from WITHIN an MXML Component". With proper communication set up, you can have the Applet and the SWF simply communicating with each other through an external set of processes.Okay, how would I get say the bitmapData of the Java object, as I would any other flex component?var myBitmap:BitmapData =new BitmapData(myTextArea.width,myTextArea.height, true, 0x00000000);var m:Matrix = new Matrix();m.scale(1, 1);myBitmap.draw(myTextArea, m);
Joshua
Depends on what you have available. Applets are able to output the bitmap to the local file system (or, more likely, a remote server) and then pass the URL of the new bitmap to Flash. Flash can then load the bitmap and manipulate it to do what it will. I do not know the calls the applet would need to make, but I am fairly certain that it is doable.
Christopher W. Allen-Poole
But I don't have the source code for the java programs or any control over them at all. The bitmap I need to read the pixels of is not a bmp resource of the java app but the visual representation of the apps gui itself.
Joshua