tags:

views:

36

answers:

1

Let's say I hav:

  1. a C library libfoo,
  2. a package org.foo.jni of JNI bindings to libfoo, and
  3. a package com.user.of.foo of client code.

Obviously, if functions that org.foo.jni touches in libfoo change, I need to recompile the classes in org.foo.jni. And, also obviously, if methods that com.user.of.foo touches in org.foo.jni change, I need to recompile the classes in com.user.of.foo. But...

  • If I change libfoo to fix a bug, but don't change the interface, do I have to recompile the classes in org.foo.jni?
  • If I change the interface to libfoo, but only in functions not called from org.foo.jni, do I have to recompile the classes in org.foo.jni?
  • If I recompile the classes in org.foo.jni because of some change in libfoo, but don't change the interface to org.foo.jni, do I have to recompile the classes in com.user.of.foo?
+3  A: 

If I change libfoo to fix a bug, but don't change the interface, do I have to recompile the classes in org.foo.jni?

No. If the interfaces do not change, then the java code/interface code does not need to be recompiled. This is part of the power of JNI code - the interfaces can remain the same, while the underlying system-specific implementation can change.

If I change the interface to libfoo, but only in functions not called from org.foo.jni, do I have to recompile the classes in org.foo.jni?

Whether or not you have to, you should, IMO. The classes will probably work, although if you are wrong, you will get an exception (UnimplementedMethod exception, iirc)

If I recompile the classes in org.foo.jni because of some change in libfoo, but don't change the interface to org.foo.jni, do I have to recompile the classes in com.user.of.foo?

No, for the same reasons in your first question. The point of the interface is that the two are separate concerns, and can be developed and compiled separately.

One way to think about JNI is the use the example of a serial port. The underlying implementation of the serial port must adhere to the interface, and the calls from Java must adhere to the interface. The two can be developed separately (and in fact almost always are) and at different times. If the interface changes, both must change to update to the new interface.

Hope that helps.

aperkins