1

does somebody has experience or does anybody know if it is possible to make working Objective C and Java in one application running on Mac ? For example, is it possible to have GUI layer coded in Objective C and Business layer in Java ?

My case is that I don't want to rewrite all the business layer from java to objective c, but my gui layer looks not good on new retina display using swing.

So in the best scenario I'd like just to call Java API from Objective C gui code.

Lubos
  • 1,169
  • 10
  • 19

3 Answers3

1

Yes; for example you could export your business layer through web services in Java and create a client for those web services in Objective C.

Random42
  • 8,989
  • 6
  • 55
  • 86
1

Definitely you can do this.

You can use your Mac OSX only for showing the output and taking user inputs and send all response/requests to a Java Based server through xml/json/soap etc.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • sorry my bad, I meant standalone desktop application not web application – Lubos Mar 12 '13 at 14:08
  • even then u need to send ur data through tcp/ip layer. so u need xml and all – Anoop Vaidya Mar 12 '13 at 14:16
  • @Lubos - you can bundle an app server with your application in order to implement what AnnopVaidya is talking about. So for example, Jersey+Grizzly (embedded server) – Perception Mar 12 '13 at 14:16
  • @Perception - that could be also option, but as you sad I'd have to include app server. I am looking for more simple solution. I'd like to bundle just JRE 7(8) with my app (no additional server). – Lubos Mar 12 '13 at 14:25
  • @Lubos: then you can go with File-System kind of app. Write your data from Java to local disk as a file, and read it from cocoa, and display it on the GUI. – Anoop Vaidya Mar 12 '13 at 14:32
  • @Perception: What about using File-System, as I just commented above :) – Anoop Vaidya Mar 12 '13 at 14:32
  • The point is that I need to invoke Java API from Cocoa, e.g. the clicking on the button should invoke some java business layer method to execute business logic and then GUI refresh based on the executin. The application is the classic desktop application with event handling code. – Lubos Mar 12 '13 at 14:39
  • So your question is different than what you want to have? – Anoop Vaidya Mar 12 '13 at 14:43
  • @Lubos - bundling the Java code into your app the way you are describing would be ***much*** more complicated. You would need to write *alot* of JNI code. – Perception Mar 12 '13 at 14:47
  • @AnoopVaidya - yes, a form of local RPC is also an option. Not sure if file based communication is the way to go (would probably run into file locking problems, buffer clear issues etc). But its entirely possible to implement the local RPC using piped sockets or a multitude of other networking options. – Perception Mar 12 '13 at 14:48
  • Maybe I was not too specific (sorry for that), but basically I wrote I want to integrate Java and Objective C in one standalone application running on Mac which implies I need to find way how to call Java from Objective C code. – Lubos Mar 12 '13 at 14:52
  • The best option (as far as i have learnt) I have already mentioned, local server and xml/soap etc transmission. – Anoop Vaidya Mar 12 '13 at 14:54
  • Ok, so the result of this discussion is (as I understood it) that you recommend 2 options: (1) either to have 2 applications and connect them through xml communication or (2) its possible to have both layers in 1 application, but I would have to write a lot of JNI code (P.S. I always thought that JNI is invoked from Java not the other way around :) ). – Lubos Mar 12 '13 at 15:09
  • @Lubos - take a look [here](http://stackoverflow.com/a/5621879/680925) for a starter on calling Java code from C, using JNI. – Perception Mar 12 '13 at 15:25
0

You could convert your application to a sort of server/client model and use IPC to connect the two applications together.

ldam
  • 4,412
  • 6
  • 45
  • 76
  • That sounds interesting, but complicated at the same time (but maybe I'm mistaken and its simple :)). In the best case I'd like just to call java API from my Objective C code. So you meant this ? – Lubos Mar 12 '13 at 14:27
  • @m3th0dman's solution is actually a better idea in terms of complexity, but it does mean you need a web server. If you went with an IPC approach you'd probably have to make an API on the Objective C side that will connect to your java application and give it the necessary commands and instructions. I can't say it will be an easy task if you don't plan it thoroughly. – ldam Mar 12 '13 at 16:31