tree: 1c23bd4ea0217ff6d1b680c996e1ae923a4eb3f2 [search]
  1. .cargo/
  2. .mvn/
  3. src/
  4. tools/
  5. .gitignore
  6. Cargo.toml
  7. CONTRIBUTING.md
  8. DEPENDENCIES.md
  9. DEPENDENCIES.rust.tsv
  10. mvnw
  11. mvnw.cmd
  12. pom.xml
  13. README.md
  14. upgrade.md
  15. users.md
bindings/java/README.md

Apache OpenDAL™ Java Bindings

Maven Central Website

A native Java binding for Apache OpenDAL™: access S3, GCS, Azure Blob, the local filesystem, and many more services through one API.

We release the OpenDAL Java binding independently of the opendal crate (Rust core). For updates and compatibility, use the Java binding version instead of the opendal crate version.

Useful Links

Installation

The all classifier bundles the Java API and the JNI libraries for all seven published platforms. Declare a single Maven dependency to compile and run without an OS detector plugin or a separate platform JAR.

<dependency>
  <groupId>org.apache.opendal</groupId>
  <artifactId>opendal</artifactId>
  <version>${opendal.version}</version>
  <classifier>all</classifier>
</dependency>

For Gradle, use implementation "org.apache.opendal:opendal:$opendalVersion:all". The all JAR is about 200 MB. To download only the native library for your target platform, use the default JAR and a platform classifier as shown below.

Maven

<build>
<extensions>
  <extension>
    <groupId>kr.motd.maven</groupId>
    <artifactId>os-maven-plugin</artifactId>
    <version>1.7.0</version>
  </extension>
</extensions>
</build>

<dependencies>
  <dependency>
    <groupId>org.apache.opendal</groupId>
    <artifactId>opendal</artifactId>
    <version>${opendal.version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.opendal</groupId>
    <artifactId>opendal</artifactId>
    <version>${opendal.version}</version>
    <classifier>${os.detected.classifier}</classifier>
  </dependency>
</dependencies>

Gradle

plugins {
    id "com.google.osdetector" version "1.7.3"
}

dependencies {
    implementation "org.apache.opendal:opendal:$opendalVersion"
    implementation "org.apache.opendal:opendal:$opendalVersion:$osdetector.classifier"
}

On musl-based Linux distributions such as Alpine, use the linux-x86_64-musl or linux-aarch_64-musl classifier instead of the detected one.

Build with additional services

The native JARs on Maven Central use the opendal dependency features in the binding's Cargo.toml, with SFTP enabled on Unix targets.

Java layers such as RetryLayer and ConcurrentLimitLayer are built in. Exposing a new Rust layer requires Java and JNI binding code.

To add a service, add its feature name, such as "services-d1", to the opendal feature list and run this from bindings/java:

./mvnw clean package -DskipTests=true

Use the resulting JARs in target/, including the JAR with your platform's classifier.

Quickstart

import java.util.HashMap;
import java.util.Map;
import org.apache.opendal.AsyncOperator;

public class Main {
  public static void main(String[] args) {
    final Map<String, String> conf = new HashMap<>();
    conf.put("root", "/tmp");

    try (AsyncOperator op = AsyncOperator.of("fs", conf)) {
      op.write("/path/to/data", "Hello world").join();
      System.out.println(new String(op.read("/path/to/data").join()));
    }
  }
}

Use the synchronous Operator for blocking calls, or AsyncOperator for CompletableFuture-based calls.

Reuse a reader

Operator.createReader(path, readerOptions) creates an OperatorReader for repeated reads. ReaderOptions selects versions, conditions, and execution controls; each call selects its own byte range.

ReaderOptions options = ReaderOptions.builder().chunk(8 * 1024 * 1024L).build();
try (OperatorReader reader = op.createReader("large.bin", options)) {
    byte[] first = reader.read(0, 1024);
    byte[] next = reader.read(1024, 1024);
}

The Java task guide covers streams and resource lifetimes. See ReaderOptions for all supported options, defaults, and constraints.

Documentation

The full user guide — getting started, connecting to services, common tasks, and going to production — lives at opendal.apache.org/docs/bindings/java.

Contributing

The Maven source-release.zip includes bindings/java and the Rust core workspace. After extracting it, run ./mvnw package from bindings/java. The wrapper downloads its JAR on first use; the source archive does not bundle it.

This project is built upon the native OpenDAL library and depends on JDK 8 or later. See CONTRIBUTING.md for how to build the binding, run tests, and apply the code style.

Used by

Check out the users list for more details on who is using OpenDAL.

License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.

Compiled distributions include the following Mozilla Public License 2.0 components. Their source code is available from the linked project pages:

Third-party software

The distribution includes the MPL-2.0 text in META-INF/LICENSE-MPL-2.0.txt.