To be able to call methods implemented by Java classes from Objective-C, you need to make the C code aware of the interface of the Java classes by creating an interface file ( | .h) describing the methods implemented by the class. Regarding parameter types, you must follow the guidelines of the Apple documentation. (For those still having a Jaguar partition with the developer tools, there was another documentation relative to the JavaBridge in /Developer/Documentation/Cocoa/Legacy/JavaBridge and for those who don't have it, we have put a copy here).
To create an instance of a Java class from Objective-C, you first use Class myJavaClass = NSClassFromString(@"MyJavaClassName") to get the class and then id myJavaObject = [[myJavaClass alloc] init];. This will call the MyJavaClassName() constructor.
To invoke another constructor, read the Javabridge documentation.
Note that MyJavaClassName must be the full Java class name using the Java path convention (e.g. "java.lang.object").
To invoke Objective-C classes from Java, read the NSSelector documentation.
There is also a good article on the Java Bridge at Cocoa DevCentral with some useful follow-ups.
Here an example on how to use the Datavision reporting engine from an Obj-C Cocoa application.
This example will also show you how to add .jar files to your project.
|