Installation

Lindera Java is the jar dev.lindera:lindera, which has the native library of the binding for each platform: adding the jar is all a program does.

Prerequisites

  • Java 21 or later: the classes are compiled for Java 21
  • A supported platform (below)

Adding the jar

From the release after 7.3.0, the jar has a version for each release of Lindera, on Maven Central. With Maven:

<dependency>
  <groupId>dev.lindera</groupId>
  <artifactId>lindera</artifactId>
  <version>VERSION</version>
</dependency>

With Gradle (Kotlin DSL):

dependencies {
    implementation("dev.lindera:lindera:VERSION")
}

The version of the jar is the version of Lindera, and the jar has the native library of that version.

On Java 24 and later, a program enables the native access of the jar, or the JVM warns when the library is loaded:

java --enable-native-access=ALL-UNNAMED -cp app.jar:lindera.jar com.example.Main

On the module path, the module is dev.lindera (--enable-native-access=dev.lindera).

Platforms

The jar has the native library for each of these platforms, and loads the one of the machine with nothing to set:

PlatformDirectory in the jarLibrary
Linux on x86_64 (glibc)dev/lindera/native/linux-x86_64/liblindera_java.so
Linux on arm64 (glibc)dev/lindera/native/linux-aarch64/liblindera_java.so
macOS on x86_64dev/lindera/native/macos-x86_64/liblindera_java.dylib
macOS on arm64dev/lindera/native/macos-aarch64/liblindera_java.dylib
Windows on x86_64dev/lindera/native/windows-x86_64/lindera_java.dll
Windows on arm64dev/lindera/native/windows-aarch64/lindera_java.dll

The library for Windows on arm64 is in the jar, and is not run by the tests of Lindera. The jar has no library for musl (Alpine Linux) and for Android: there a program uses a library built from the sources (below).

The first use of Lindera copies the library out of the jar, into a directory under java.io.tmpdir named after the version and the SHA-256 of the library, and loads it from there. Where the temporary directory does not allow a library to be loaded (mounted noexec), the system property dev.lindera.library.dir names another directory:

java -Ddev.lindera.library.dir=/var/lib/myapp/native ...

A library of one's own

When the system property dev.lindera.library.file, or else the environment variable LINDERA_JAVA_LIBRARY_FILE, names a file, the jar loads the native library from that file instead of the one it has:

java -Ddev.lindera.library.file=/path/to/liblindera_java.so ...
# or
export LINDERA_JAVA_LIBRARY_FILE=/path/to/liblindera_java.so

It is for a platform the jar has no library for, and for a library built from the sources, with an embedded dictionary for example:

cargo build --release -p lindera-java --features embed-ipadic
# target/release/liblindera_java.so

A file that is not there, or cannot be loaded, is an UnsatisfiedLinkError that names it, and the jar does not fall back to its own library. The library must be of the version of the jar (see Versions and features).

The native library is that of the crate lindera-java, which is not the library of the C API (LINDERA_LIBRARY_FILE of Lindera .NET names that one).

Development

The Makefile has the targets of the binding:

make format-lindera-java      # cargo fmt, and google-java-format on the Java sources
make lint-lindera-java        # clippy, and fail when google-java-format would change a file
make test-lindera-java        # the JNI layer, the tests in Java and Kotlin, and the jar
make check-docs-lindera-java  # rustdoc of the JNI layer and Javadoc, with the warnings as errors

make test-lindera-java runs the unit tests of the JNI layer, builds its library with the features of the tests (embed-ipadic,train,dependency,test-hooks), and runs the tests in Java and in Kotlin with that library, under -Xcheck:jni, with the Maven Wrapper (lindera-java/mvnw). It then makes a jar with that library, which a Maven project of its own, in Java and in Kotlin, adds and runs (scripts/test_lindera_java.sh). It needs Java 21 or later; the wrapper fetches Maven.