JNI & Cocoa

phil

Registered
Can a Java application call a cocoa library ?
I'd like to create a library using the cocoa features and call this library from my Java application using JNI.

For test purpose, I created a simple library which just loads a nib, but all I got is this exception :
"[NSJavaVirtualMachine initWithClassPath:] - cannot instantiate a Java virtual machine"

the entry point in the library looks like that :
JNIEXPORT void JNICALL Java_hello_test(JNIENV*env,jclass jc)
{
[NSBundle loadNibNamed:mad:"sample" owner:nil];
}

By the way, will I need to call [NSApp run] as if it was an application ?


Any help appreciated.
 
Java has been made for portability, that means a Java app can work on any computer and that's why you MUSN'T use elements of the Cocoa API with your Java apps.

Therefor, Cocoa API includes Java, so you can build your Cocoa apps in Java:)
 
If you still want to use Cocoa API with your Java apps, you have to import cocoa.AppKit and cocoa.fundations (the import method)
 
Thanks for your advice about portability but if I need to use JNI, there IS a reason : that's because I need to call system dependant functions that are not available through Java.

Anyway, I managed to use Java Bridge to do what I want.
 
We have the need to do this as well and we do have a good reason.
Reason: cocoa has great libraries in coregraphics to generate thumbnails for pdf files however cocoa is total crap when for things like running an xml-rpc server. So in this case we need our Java xml rpc server to receive calls and pipe them into cocoa cleanly. Is there any way to do this?
 
Back
Top