Announcement Announcement Module
No announcement yet.
problem with native code Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

  • #2
    problem with native code


    FindClass(JNIEnv*, char*) looks only on the configured classpath for classes (

    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.



    • #3
      problem with native code

      Ah that explains it. I guess I'll have to modify the library. Thanks.


      • #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() {"Something Happened");

        private void doSomething() {"Starting native app");
        NativeApp app = new NativeApp(new ListenerImpl());

        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.


        • #5
          problem with native code

          And another weird thing...

"{} {} {}", 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 {} {}