This project implements a Java-based file synchronization service for Nextcloud using native libraries via the Foreign Function & Memory API (FFM API). Native interactions with libcurl
are exposed in Java through automatically generated bindings using jextract
.
- Java 22 with Foreign Function & Memory API
- Native C library (
libsync.so
) using libcurl and libxml2 - REST API built with Quarkus
- Folder watcher that uploads files on change
- Uses
jextract
for generating Java bindings (no JNI)
native-worker/ # C source code (sync.c, sync.h) quarkus-service/ # Quarkus-based Java REST service src/main/java/ # jextract-generated Java bindings libsync.so # Compiled native shared library
- Upload local files to Nextcloud via HTTP PUT
- List remote folders using WebDAV PROPFIND
- REST endpoints to trigger upload or folder listing
- File watcher that observes a local directory
- Fully JNI-free native integration using
jextract
and the FFM API
cd native-worker gcc -fPIC -shared -o libsync.so src/sync.c -lcurl -lxml2
Make sure libsync.so is discoverable via the JVM (e.g., by setting LD_LIBRARY_PATH or placing it in the project root).
### Run jextract
jextract --source \
--target-package com.nativecloud.sync \
--output src/main/java \
-I include \
include/sync.h
or use the run script run.sh
cd quarkus-service ./mvnw compile quarkus:dev
The service reads the following environment variables:
Example:
export NEXTCLOUD_URL="https://cloud.example.com/remote.php/dav/files/admin/"
export NEXTCLOUD_USER="admin"
export NEXTCLOUD_PASSWORD="secret"
export WATCH_DIR="/home/user/sync-folder"