Re: Finding jnilib on Xcode (that's linked to dylib file)
Re: Finding jnilib on Xcode (that's linked to dylib file)
- Subject: Re: Finding jnilib on Xcode (that's linked to dylib file)
- From: Greg Guerin <email@hidden>
- Date: Fri, 6 Oct 2006 19:05:57 -0700
Jack Nutting wrote:
>> What setting do I need to do so that the application could find the jnilib?
>
>I encountered similar problems recently. First, are you passing the
>full path to your jnilib to System.loadLibrary()? If so, you
>shoudn't; you just just pass the name of the lib WITHOUT the .jnilib
>extension, and it should be able to find it in the java path (e.g. the
>current directory or /Library/Java/Extensions). However, this didn't
>actually work for me. What I ended up doing is passing the full path
>of my jnilib, INCLUDING the .jnilib extension, to System.load()
>instead of loadLibrary(), and that works fine.
If you have a Cocoa-Java application, then you have to do it that way,
though how the absolute pathname is generated can use Cocoa-Java classes,
which makes it more "movable" without breaking the JNI-lib loading. I
solved this by writing a LibLoader class:
<http://lists.apple.com/archives/java-dev/2006/Apr/msg00083.html>
If you don't have a Cocoa-Java app, you can probably just set the
"java.library.path" key in the Java/Properties dictionary of Info.plist.
In general, if you have to use an absolute path anywhere except a
Cocoa-Java app, there's probably another way to do it that's more flexible.
I realize this is vague, but the details of the application and its
environment make a big difference to choosing an effective strategy. There
is no single universal answer, nor is there a single reason why it can
fail. It even depends on the environment one is executing from, and Xcode
vs. stand-alone has different results. See the section "Connecting
Everything Together" near the end of this article:
<http://developer.apple.com/java/jniuniversal.html>
There isn't enough information in the original post for me to tell exactly
what's wrong, nor to figure out what will make it work.
>Perhaps macosx-dev would have been more appropriate?
Java-Dev would be better.
- - - -
Inge Yuwono originally wrote:
>In the link above, there's no instruction to specify the
>java.library.path by adding option -D to jvm.
The article's example target is created from Xcode's Java Swing Application
template. When such a target is built, the app's native executable is a
Java launcher copied into place from JavaVM.framework. That launcher reads
Info.plist for properties, and also predefines some properties based on its
own self-knowledge. One property it predefines is "java.library.path", to
a value that includes Contents/Resources/Java/ within the app-bundle
itself. So under normal circumstances and by default, you don't have to
define java.library.path. It will just work.
However, if the Xcode build doesn't copy the JNI-lib into
Contents/Resources/Java/, then the predefined java.library.path is in vain.
See "Connecting Everything Together" above.
>Exception in thread "main" java.lang.UnsatisfiedLinkError:
>/Users/inge/Documents/NetBeansProjects/ImageViewer/build/Release/libImageDecomp
>ressor.jnilib:
>..
> at java.lang.System.loadLibrary(System.java:992)
>..
This looks like it's trying to load the JNI lib from the build directory,
rather than from its location within the app-bundle. Without seeing
source, I can't tell what the code is attempting, though. See the URLs I
cited above.
You might get a better answer by posting to Java-Dev, and further
describing what you've changed from the original JNI Universal example.
Targets, build settings, Java source, C source, and frameworks can all
cause a JNI lib to not load correctly, and any of those causes has pretty
much the same Java exception: UnsatisfiedLinkError. It is possible to
create apps and use JNI libs in them, but without details, it's impossible
to guess what the correct remedy should be.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden