codemp/dist/java
2024-09-15 02:00:04 +02:00
..
src/mp/code feat(java): get_user, active_workspaces 2024-09-15 02:00:04 +02:00
build.gradle fix(java): bundle mac binaries too 2024-09-09 20:59:07 +02:00
README.md docs: moved around documentation 2024-09-13 22:56:00 +02:00
settings.gradle chore: cleanup, reorganizing java glue 2024-08-08 00:29:54 +02:00

Java bindings

codemp's Java bindings are implemented using the JNI.

On the Rust side, all Java-related code is gated behind the java feature, and is implemented usingjni-rs. Unlike other supported languages, Java is statically typed and requires knowing all foreign function types at compile time. This means that, to use codemp from Java, all functions which will be used must be declared (as native), making using our Java binding without extra glue extremely tedious.

We provide glue code also on the Java side, wrapping all native calls and defining classes to hold codemp types.

Building

This is a Gradle project: building requires having both Gradle and Cargo installed, as well as the JDK (any non-abandoned version). Once you have all the requirements, building is as simple as running gradle build: the output is going to be a JAR under build/libs, which you can import into your classpath with your IDE of choice.

Development

The Java bindings have no known major quirk. However, here are a list of facts that are useful to know when developing with these:

  • Memory management is entirely delegated to the JVM's garbage collector.
    • A more elegant solution than Object.finalize(), who is deprecated in newer Java versions, may be coming eventually.
  • Exceptions coming from the native side have generally been made checked to imitate Rust's philosophy with Result.
    • JNIExceptions are however unchecked: there is nothing you can do to recover from them, as they usually represent a severe error in the glue code. If they arise, it's probably a bug.