Re: loading nib from jnilib - now java from cocoa!
Re: loading nib from jnilib - now java from cocoa!
- Subject: Re: loading nib from jnilib - now java from cocoa!
- From: Mary Waller <email@hidden>
- Date: Tue, 18 Feb 2003 16:39:32 +0000
I'm trying to access a nib (or even the classes used to create it
programmatically) from a java application.
We have quite a large java application - mainly Swing. There are certain
things we can't do cross-platform, and have had to implement in other
ways (usually using platform specific libraries). One such thing I have
achieved with the classes in the nib.
I am presently attempting - as a last resort while I still have some
hair - to 'wrap'the java application as a cocoa one, by calling my main
class's main function from cocoa (using ProjectBuilder).
So far so good, but (in spite of the excellent well publicized tutorial
on the Java bridge) I can't load any java classes from the cocoa
application - NSClassFromString always returns nil.
I've even written headers for the java classes I'm trying to load, so
it's not that.
This is what I have so far, in the application's main.m:
int main(int argc, const char *argv[])
{
Class javaClass;
NSString * javaClassName;
NSAutoreleasePool * pool;
pool = [[NSAutoreleasePool alloc] init];
if(!pool){
NSLog(@"pool isnil");
return 1;
}
//attempt to bully JVM into correct classpath
[[NSJavaVirtualMachine alloc] initWithClassPath:
[[NSJavaVirtualMachine defaultClassPath]
stringByAppendingString:@":/Contents/Resources/Java/CocoaDraw.jar"]];
[NSApplication sharedApplication];
// this is a simple class not in the application package that exists
solely to call main on
// the main class. Wasn't sure if packages were confusing things!
javaClassName = @"CocoaDraw";
// this always returns nil :(
if(javaClass = [[NSClassFromString(javaClassName) alloc] init]){
[javaClass callMain:argv];
}
NSLog(@"javaclass is %@ for name %@",javaClass,javaClassName);
//this works beautifully though!!
[NSBundle loadNibNamed:@"JCMacAnn" owner:NSApp];
// if this isn't here the application returns straight away
[NSApp run];
[pool release];
return 0;
}
Amul Goswamy wrote:
What are you trying to do? Loading a nib involves a whole runtime
that AppKit provides, thus it can't be done from a pure Java
application. There is always Cocoa Java. Cocoa-Java lets you use
AppKit and Foundation classes while writing in Java.
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/
ApplicationKit/Java/Intro/IntroAppKit.html#//apple_ref/doc/uid/20000690
Amul Goswamy
Interface Builder QA
Apple
On Friday, February 14, 2003, at 01:25 AM, Mary Waller wrote:
I have a nib containing a NSPanel, which has as it's file owner a
subclass of NSWindowController.
If I load the nib from a Cocoa app it behaves just as I want, but if
I try and load it from a java application using objC in a jnilib I
either get the java app hanging or it exits with "exited due to
signal 5 (SIGTRAP)" just after this:
- (id)init
{
if(self = [super initWithWindowNibName:@"NibName"]){
NSLog(@"WindowController - init called"); // this is printed
out OK
return self;
}
Is it possible to load a nib from a jnilib?
What does NSApplication do that I'm not doing from the jnilib?
I tried writing it in Java, but you can't use AppKit classes from
pure Java so that fell flat :(
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.