$darkmode
Elektra 0.11.0
|
Allows you to write plugins in Java.
This plugin needs the JNA bindings to work. Furthermore, it requires Java 11 or later.
While the plugin internally uses JNI (thus the name), the Java binding for your Java plugin may use something different, e.g. JNA. The requirements for the Java bindings are:
elektra/Key
and elektra/KeySet
withThe Java plugin itself needs to have the following methods:
elektra/KeySet
(the plugin's conf) and elektra/Key
elektra/Key
elektra/KeySet
and elektra/Key
elektra/KeySet
and elektra/Key
elektra/KeySet
and elektra/Key
See installation. The package is called libelektra5-java
. To actually mount plugins, you will additionally need java-elektra
. Furthermore, at least JNA version 5.5 is required.
You need to pass :
elektra/plugin/Echo
Additionally, you can set:
-verbose:gc,class,jni
false
If Elektra and a recent jna.jar (adapt path below) is already installed, following should output some debug logs and this README:
Note: The Java implementation of the plugin can request any other additional plugin configuration, read about it in the end of the output of plugin-info. Plugins dynamically append text after the end of this page.
You can also mount plugins (see open issues):
If you do not want to use pre-compiled versions, you can compile the plugin yourself. Start by enabling the plugin using (ALL;-EXPERIMENTAL
is default):
Install package openjdk-11-jdk
and make sure that no older Java versions are present in /usr/lib/jvm
.
If you have manually installed Java, you might get errors related to Could NOT find JNI
during cmake
. In this case, please consider setting your JAVA_HOME
environment variable accordingly.
Older macOS include an old apple specific version of Java, based on 1.6. However, for the jni plugin JDK version 11 is required, so either the openjdk or the oracle jdk has to be installed.
For example, install oracle's jdk11 via their provided installer. After that, you have to set the JAVA_HOME environment variable to the folder where the jdk is installed, usually like
As macOS handles linked libraries differently, there is no ldconfig command. Instead you can export an environment variable to tell Elektra the location of Java's dynamic libraries.
Afterwards, the jni plugin should be included in the build and compile successfully.
Make sure to run the test after compiling the plugin. Change to your Elektra's build folder and execute the following command for running the JNI plugin test and verify it works:
If it should still not find the correct jni version, or says the jni version is not 11, then it most likely still searches in the wrong directory for the jni header file. It has been experienced that if the project has been built already without this environment variable set, the Java location is cached. As a result, it will be resolved wrong in future builds, even though the environment variable is set. To resolve this, it should be enough to delete the CMakeCache.txt file in the build directory and reconfigure the build.
To know how the methods of your class are called, use:
Also explained here