-
Sep 22nd, 2008, 01:48 PM
#1
problem with native code
I depend on a library that has native code. I created a bundle from that library, but it's not working as expected.
The native code calls
_env->FindClass("name/of/class")
where the class is the same class that contains references to native methods
the function returns NULL even though it's the same class that causes the native methods to be invoked.
I'm guessing it's something to do with the way classloading works? I know little about JNI. Any ideas on how to address this?
-
Sep 23rd, 2008, 03:36 AM
#2
problem with native code
Vadim,
FindClass(JNIEnv*, char*) looks only on the configured classpath for classes (http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/functions.html#wp16027).
I think the best option is to pass in the class into your native code. If this is not possible, you'll need to locate the correct ClassLoader in native code and then invoke loadClass() on it.
Rob
-
Sep 23rd, 2008, 06:15 AM
#3
problem with native code
Ah that explains it. I guess I'll have to modify the library. Thanks.
-
Sep 26th, 2008, 01:06 PM
#4
problem with native code
Thanks, I modified the native code to pass a reference to the original class and that works, but there's a strange issue with logging.
The native code has callbacks that end up firing listeners in Java. When using a logger (slf4j), events don't end up in the bundle's trace file. It does work outside the listener.
It's something like this:
public class ServiceImpl {
private Logger logger = LoggerFactory.getLogger(ServiceImpl.class);
private class ListenerImpl implements Listener {
void somethingHappened() {
logger.info("Something Happened");
}
}
private void doSomething() {
logger.info("Starting native app");
NativeApp app = new NativeApp(new ListenerImpl());
app.start();
}
}
The log statement in doSomething will show up in the bundle's trace file, but the listener log statement wont.
They both show up in the global trace file.
-
Sep 26th, 2008, 01:45 PM
#5
problem with native code
And another weird thing...
logger.info("{} {} {}", new Object[] { "aaa", "bbb", "ccc"} );
Outside of spring dm server, this outputs
aaa bbb ccc
Inside dm server, this just outputs
[Ljava.lang.Object;@158ae49 {} {}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules