javajava-native-interfacewrapperglibgobject-introspection

How can I use GObject Introspection to generate Java bindings?


I need to use the GLib library in the spice-gtk. Since, it’s a GLib library, that means I can use GObject introspection to generate Java bindings. I have found out that I need to get GIR XML files from either compiling or from prebuilt libraries here. That’s cool and all, but how do I actually generate the Java bindings?

I‘ve looked at a questions asked about this and documentation online, but it doesn’t seem to tell you how to actually start the process.


Solution

  • The answer was found on the GNOME Discourse Forums. All that needed to be done was search on Google for "Java GObject introspection bindings generator."

    Several tools have been created throughout the years that generate Java bindings with GObject introspection. They include JGIR (which was one click away on the GObject guide), gir2java, and Java-GI.

    Java-GI is the most prominent today. This tool has the advantage of it using the new Foreign Function & Memory API. The disadvantage is that the API is experimental, and it of course doesn't use JNI which would be better for backward-compatible Java apps/plugins.

    Unfortunately, there seems to be no other tool that can use GObject introspection besides Java-GI if someone wishes to use JNI. The only options left would be to manually create a library with JNI or use a wrapper generator like SWIG to generate a library.