Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Java Program from a Cocoa Application

I can't find a decent Cocoa Charting Library so I would like to use JFreechart.

Is there any way to call a Java program from a Cocoa Application? I was thinking in writing a java application that returns an image of the chart and I would display it inside my Cocoa app.

Thank you,

like image 852
simao Avatar asked Dec 08 '22 05:12

simao


2 Answers

You may want to look at the Core Plot framework, a Cocoa-native plotting framework for Mac and iPhone. It's relatively new--not as mature as JFreeChart--but it may do what you need. It would certainly save you the pain of JNI or inter-process hackery.

like image 189
Barry Wark Avatar answered Dec 18 '22 08:12

Barry Wark


Apple has a very good (but somewhat old) sample code project of how to create an app that uses JNI in Xcode:

http://developer.apple.com/java/jniuniversal.html

Be sure to check out the sample code associated with that:

http://developer.apple.com/samplecode/MyFirstJNIProject/MyFirstJNIProject.html

Also this Tech Q&A:

http://developer.apple.com/mac/library/qa/qa2005/qa1295.html

I used that example to successfully create an app which uses JNI to launch and communicate with a single JVM instance at runtime (rather than spawning lots of NSTasks as Pablo mentioned in #2 below). Basically, i took the approach of Pablo's 1st suggestion below with this app:

http://ditchnet.org/xslpalette

like image 35
Todd Ditchendorf Avatar answered Dec 18 '22 07:12

Todd Ditchendorf