Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JNI work fine with default Java5 but not with javase6dp8



Greg Guerin wrote:

Youssef wrote:

Before thinking to build and call directly my native code, my java classes called directely
NSDistributedNotificationcenter constructor (deprecated since i don't found an other class replacing it, this is an other
headache ). but this constructor throw this exception:
NSRuntime.loadLibrary(/usr/lib/java/libObjCJava.dylib) error.
java.lang.UnsatisfiedLinkError: /usr/lib/java/libObjCJava.A.dylib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1702)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1005)
at com.apple.cocoa.foundation.NSRuntime.loadLibrary(NSRuntime.java: 127)
at com.apple.cocoa.foundation.NSRuntime.<clinit>(NSRuntime.java:35)
at com.apple.cocoa.foundation.NSObject.<clinit>(NSObject.java: 27)
the same error that i have had when cc commandline generated 32-bit by default rather than 64-bit.
From this error, I think that calling NSDistributedNotificationcenter ,automatically calls libObjCJava.dylib and found
that this lib is for 32-bit architecture only.

The com.apple.cocoa classes are part of the Cocoa-Java API, and are not
supported moving forward from 10.4, when they were deprecated. Since
64-bit Java is a move forward, there are no 64-bit Cocoa-Java classes.


If you want to use 64-bit Java, you must remove all the Java code that
refers to any com.apple.cocoa class.  After you do that, the
NSRuntime.loadLibrary() java.lang.UnsatisfiedLinkError will go away.

You do not need to link your 64-bit JNI-lib with any lib in /usr/lib/ java.

If you must use Cocoa functions from Java, you have two options:
 1) Only run under the 32-bit JVM, so you can call Cocoa-Java.
 2) Write a JNI library that calls the native Cocoa functions,
      then call that jnilib from your Java class.

There are other issues with many of the Cocoa-Java classes, even in 32- bit JVMs. They are all intended for use in Cocoa-Java programs, and many have the caveat that they must only be used from the AppKit thread. That thread is not easily available in a normal Java app. Failure to follow that rule can result in deadlocks or crashes, seemingly at arbitrary times. Such apps can run fine on one machine, and crash-and-burn on another. Or it could work fine for years, and then after a point update from Apple it starts crashing or hanging everywhere.


If you really need access to the NSxxx classes, JNI is pretty much required (although there are some 3rd party products that may negate the need for you to write the native code yourself, e.g. rococoa).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden


This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.