Getting Started with Java
To use the library, we recommend you update Rust to the latest stable version
$ rustup update stable. Nightly should be fine but some changes might not be compatible.
Ensure you have installed the required dependencies for the library first. Then, you can also install the following programs:
- Java & JDK (Make sure $JAVA_HOME env variable is set).
- Gradle v4 or higher or Maven.
- Cargo ndk (
cargo install cargo-ndk).
- Cargo fmt (
rustup component add rustfmt).
Download or clone the
git clone -b production https://github.com/iotaledger/wallet.rs.git
In a production setup, do not store passwords in the host's environment variables or in the source code. See our backup and security recommendations for production setups.
To build using the Wallet.rs Java bindings, you will need:
- JNI Native library linking
C, and then
.dylibdepending on your system).
- Java archive(Jar) containing
nativemethods which call C code. (
Step 1: Creating the Native Library
Build the wallet library (this generates the java source code and JNI library file):
cargo build --release
You can find the generated binaries in
Compiling for Android requires additional compilation instructions.
You can find these instructions in Getting Started with Java for Android.
Step 2: Creating the Java Archive
Generating the source files and classes
After you complete step 1, you can find the Java generated source files under
If this step succeeds, you need to generate the jar file containing the newly generated Java source files.
Generating the jar
You can generate the jar file with your tool of preference. This guide provides examples for Gradle and Maven.
gradlew executable (
chmod +x gradlew) if needed, then run the following commands from the project root:
After running one of these commands, you can find the jar file at
You can find more information on using the
wallet.rs library's java binding in the examples section.
./gradlew examples:java-app:test --info
You can run the examples using Maven by running the following command:
You can find the references for the binding's API in the Java API Reference section.
Due to the fact that tje Java binding through C to Rust, there are a few limiting factors.
- Classic builder patterns return a
cloneafter each builder call since we can only pass back to C by reference in
Rustas shown in the example below.
Builder builder1 = new Builder();
Builder builder2 = builder1.setValue(true);
// These are different instances, thus builder1 wont have the value set