Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
Hello all,

Although I've done some Objective-C programming, I'm far more confident in coding in Java.
Is it possible for me to create a GUI using IB, writing the controller in Objective-C, and then linking the controller with a Java model?

I'm planning to code primarily for Snow Leopard (as that is my active platform). I will then look at support on Leopard for potential users who haven't upgraded.

If it is possible, how can I achieve this? Is there some documentation I should read involved in this?

Many thanks,
Ben
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
JNI:
http://en.wikipedia.org/wiki/Java_Native_Interface
http://java.sun.com/docs/books/jni/

You can embed a JVM in your C (or in this case Objective-C) program, and make calls to your java code from C (and vice versa). If you wouldn't mind making the front-end Objective-C++, using JNI is much easier from C++ rather than straight C.

-Lee

EDIT: You will have to be careful not to mix your nomenclature too much. You might get confused about whether that nib is of a cocoa bean or coffee bean. Heaven forbid you want to mix some NUTMEG into this Mochachino you're brewing up.
 

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
Many thanks Lee,

I shall look into that over the weekend if time allows.

Many thanks once again,

Ben
 

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
I've been reading through the JNI book, and in the first example, I stumbled.

It says to compile a shared library on solaris do this:
Code:
cc -G -I/java/include -I/java/include/solaris HelloWorld.c -o libHelloWorld.so

However, I'm on OS X...How can I achieve the same thing? (In XCode or on the command line)

Many thanks,
Ben
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
I've been reading through the JNI book, and in the first example, I stumbled.

It says to compile a shared library on solaris do this:
Code:
cc -G -I/java/include -I/java/include/solaris HelloWorld.c -o libHelloWorld.so

However, I'm on OS X...How can I achieve the same thing? (In XCode or on the command line)

Many thanks,
Ben
The command line options are almost identical, but the folders where the the needed include files live are different. I don't think this can be done with the XCode GUI, at least in Snow Leopard, due to XCode's lack of Java support. I'd tell you where the include folders are, but I'm not at a Mac (let alone have access to Xcode). :eek:
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
I don't think this can be done with the XCode GUI, at least in Snow Leopard, due to XCode's lack of Java support.

Xcode 3.2 has Java project templates in its Organizer window. Open the Organizer window, click the + icon below the list, and see the available templates.

Like many things in Xcode 3.2, it's not in the same place as before. For example, there used to be a control to get the detailed build log (aka build transcript). Here's the new way:
http://lists.apple.com/archives/xcode-users/2009/Oct/msg00624.html

There's a "JNI" section heading here:
http://developer.apple.com/mac/libr...Development/05-CoreJavaAPIs/CoreJavaAPIs.html

Also see:
http://developer.apple.com/mac/library/technotes/tn2005/tn2147.html
 

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
Xcode 3.2 has Java project templates in its Organizer window. Open the Organizer window, click the + icon below the list, and see the available templates.

Like many things in Xcode 3.2, it's not in the same place as before. For example, there used to be a control to get the detailed build log (aka build transcript). Here's the new way:
http://lists.apple.com/archives/xcode-users/2009/Oct/msg00624.html

There's a "JNI" section heading here:
http://developer.apple.com/mac/libr...Development/05-CoreJavaAPIs/CoreJavaAPIs.html

Also see:
http://developer.apple.com/mac/library/technotes/tn2005/tn2147.html

Cheers for that, I did wander where Java had disappears to...

Oddly enough, there is a huge difference between XCode 3.2 and XCode 3.2.1, I have the two versions on my MacBook and Mac Pro and they are fairly different in layout...

As to compiling a C file into a library, I'm still not sure, I've searched the web, but I'm obviously asking a stupid question or looking for the wrong thing...:(
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
As to compiling a C file into a library, I'm still not sure, I've searched the web, but I'm obviously asking a stupid question or looking for the wrong thing...:(

Under the "JNI" section heading here:
http://developer.apple.com/mac/libr...Development/05-CoreJavaAPIs/CoreJavaAPIs.html

there are examples of actual command-line compilation of JNI library source. That's why I posted that URL before.

If those examples don't work or don't meet your needs, be specific about how they don't work or don't meet your needs. That includes posting any error messages, rather than just saying "It doesn't work" or "It has an error".
 

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
Under the "JNI" section heading here:
http://developer.apple.com/mac/libr...Development/05-CoreJavaAPIs/CoreJavaAPIs.html

there are examples of actual command-line compilation of JNI library source. That's why I posted that URL before.

If those examples don't work or don't meet your needs, be specific about how they don't work or don't meet your needs. That includes posting any error messages, rather than just saying "It doesn't work" or "It has an error".

Aha! I'm sorry chown33, my internet is playing up and I didn't see your last two links before as only parts of the page loaded.
You link help's me very much.

Thanks you all for all your help :)
Ben
 

Nordwolf

macrumors newbie
Oct 30, 2009
11
0
Why not just do the whole application in Java + Swing if you want to use Java? The Swing look and feel in Apple's latest versions of Java is practically indistinguishable from a native Cocoa application. This would be a lot less error prone than trying to use JNI. And the Java-Cocoa bridge is deprecated, so I would not suggest using that either.

Take a look at some of the latest screen shots of NetBeans on Mac for example to see how good the look and feel has gotten. Here's a link to one: http://blogs.sun.com/stan/resource/laf/nbdev.png
 

ranguvar

macrumors 6502
Sep 18, 2009
318
2
You might want to take a look at Ken Orr's blog. He creates custom controls / views using Swing that you can then implement in your Java app. If you stick to his widgets and Swing's native-looking components, your application will look virtually undistinguishable from a native Cocoa app.
 

elppa

macrumors 68040
Nov 26, 2003
3,233
151
Take a look at some of the latest screen shots of NetBeans on Mac for example to see how good the look and feel has gotten. Here's a link to one: http://blogs.sun.com/stan/resource/laf/nbdev.png

One problem is the “unified toolbar” in NB looks like a unified toolbar but doesn't behave like unified toolbar. This is a retrograde step in my opinion because at least in previous versions the draggable area was clear.
 

ranguvar

macrumors 6502
Sep 18, 2009
318
2
One problem is the “unified toolbar” in NB looks like a unified toolbar but doesn't behave like unified toolbar. This is a retrograde step in my opinion because at least in previous versions the draggable area was clear.

Again, let me point you to Ken Orr's blog and his Mac Widgets.
His unified toolbar looks & behaves exactly like a native unified toolbar.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.